Path: csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: Marco Buttu Newsgroups: comp.lang.python Subject: Re: How come StopIteration.__base__ is not BaseException? Date: Tue, 27 Aug 2013 12:02:29 +0200 Organization: Aioe.org NNTP Server Lines: 35 Message-ID: <521C7935.8080205@gmail.com> References: <521C446B.9040605@gmail.com> <521c6fb9$0$11100$c3e8da3@news.astraweb.com> NNTP-Posting-Host: Zaj2x0c6hH7gRtbXC3UOcw.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.python:53049 On 08/27/2013 11:22 AM, Steven D'Aprano wrote: > > What matters is that when you catch "nearly everything", StopIteration is > included in the "nearly everything", but SysExit and KeyboardInterrupt > should not be. Consider: > > > try: > main() > except Exception as e: > print('an unexpected error occurred') > log_unhandled_exception(e) > emergency_shutdown() > sys.exit(1) > except (KeyboardInterrupt, SysExit): > # User wants to exit. > clean_exit() > sys.exit(0) > > > > Which except clause would you expect an unhandled StopIteration to fall > under? The unexpected error clause, or the "user wants to exit cleanly" > clause? Thanks Steven, that was clear for me. I was thinking about a design concept: how come doesn't it inherit directly from BaseException like GeneratorExit does? But I think I got the answer: because we can iterate manually and so it can propagate, and so we want an except Exception clause catches it. Thanks, Marco -- Marco