Generators and exceptions (was Re: Stackless Python and Python 2.x)
Aahz Maruch
aahz at panix.com
Thu Sep 6 14:54:12 EDT 2001
In article <mailman.999758467.20371.python-list at python.org>,
Tim Peters <tim.one at home.com> wrote:
>[Aahz]
>>
>> The part I don't understand (though if I had access to 2.2a2, I could
>> probably test it easily enough) is what happens when you re-enter a
>> generator and trigger an exception (an exception that isn't
>> StopIteration, for any smartasses out there).
>
>Nothing special: the exception is caught by the frame or not, and if not
>propagates out of the frame. Generators do nothing special at all here, and
>since they always return to their immediate invoker, there are no debatable
>issues about *which* frame *to* propagate an uncaught exception (general
>coroutines are muddier in this respect, and general continuations even
>worse).
Okay, I've re-read PEP 255, and I'm still not clear on what happens with
the following code:
def a():
yield 1
raise "foo"
yield 2
return
def b():
return a()
g = b()
g.next()
g.next()
(If I've messed up the syntax, please feel free to correct it before
answering; I *think* my intent is clear enough.)
--
--- Aahz <*> (Copyright 2001 by aahz at pobox.com)
Hugs and backrubs -- I break Rule 6 http://www.rahul.net/aahz/
Androgynous poly kinky vanilla queer het Pythonista
"Plus ca change, plus c'est la meme chose."
More information about the Python-list
mailing list