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


Groups > comp.lang.python > #53092

Re: How come StopIteration.__base__ is not BaseException?

From Terry Reedy <tjreedy@udel.edu>
Subject Re: How come StopIteration.__base__ is not BaseException?
Date 2013-08-27 16:37 -0400
References (2 earlier) <521C446B.9040605@gmail.com> <521c6fb9$0$11100$c3e8da3@news.astraweb.com> <521C7935.8080205@gmail.com> <mailman.278.1377629540.19984.python-list@python.org> <kvj01v$s20$1@speranza.aioe.org>
Newsgroups comp.lang.python
Message-ID <mailman.283.1377635844.19984.python-list@python.org> (permalink)

Show all headers | View raw


On 8/27/2013 3:52 PM, Marco Buttu wrote:
> On 08/27/2013 08:51 PM, Terry Reedy wrote:
>
>> BaseException was added just so it would be possible to catch nearly
>> everything but a few exceptions. The first two were KeyboardInterrupt
>> and SystemExit (in 2.5). GeneratorExit was switched in 2.6, but I forget
>> the details of why.
>
> Maybe in order to don't catch it inside a generator using a except
> Exception clause, because it is used to notify an active generator is
> closed:
>
>  >>> def foogen():
> ...     for i in range(10):
> ...         try:
> ...             yield i
> ...         except:
> ...             print('Catched!')
> ...             # raise
> ...
>  >>> g = foogen()
>  >>> next(g)
> 0
>  >>> g.close()
> Catched!
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
> RuntimeError: generator ignored GeneratorExit
>
> Do you remember if this is the reason? Thanks,

I only remember that there was a 'problem' that necessitated a change in 
2.6 after the introduction in 2.5. The above seems reasonable.

-- 
Terry Jan Reedy

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