Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #53049

Re: How come StopIteration.__base__ is not BaseException?

From Marco Buttu <marco.buttu@gmail.com>
Newsgroups comp.lang.python
Subject Re: How come StopIteration.__base__ is not BaseException?
Date 2013-08-27 12:02 +0200
Organization Aioe.org NNTP Server
Message-ID <521C7935.8080205@gmail.com> (permalink)
References <kvgapp$lh3$1@speranza.aioe.org> <mailman.246.1377547832.19984.python-list@python.org> <521C446B.9040605@gmail.com> <521c6fb9$0$11100$c3e8da3@news.astraweb.com>

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How come StopIteration.__base__ is not BaseException? Marco Buttu <marco.buttu@gmail.com> - 2013-08-26 21:37 +0200
  Re: How come StopIteration.__base__ is not BaseException? random832@fastmail.us - 2013-08-26 16:10 -0400
    Re: How come StopIteration.__base__ is not BaseException? Marco Buttu <marco.buttu@gmail.com> - 2013-08-27 08:17 +0200
      Re: How come StopIteration.__base__ is not BaseException? Marco Buttu <marco.buttu@gmail.com> - 2013-08-27 08:18 +0200
      Re: How come StopIteration.__base__ is not BaseException? Steven D'Aprano <steve@pearwood.info> - 2013-08-27 09:22 +0000
        Re: How come StopIteration.__base__ is not BaseException? Marco Buttu <marco.buttu@gmail.com> - 2013-08-27 12:02 +0200
          Re: How come StopIteration.__base__ is not BaseException? Terry Reedy <tjreedy@udel.edu> - 2013-08-27 14:51 -0400
            Re: How come StopIteration.__base__ is not BaseException? Marco Buttu <marco.buttu@gmail.com> - 2013-08-27 21:52 +0200
              Re: How come StopIteration.__base__ is not BaseException? Terry Reedy <tjreedy@udel.edu> - 2013-08-27 16:37 -0400
  Re: How come StopIteration.__base__ is not BaseException? Ethan Furman <ethan@stoneleaf.us> - 2013-08-27 13:00 -0700

csiph-web