generators and exceptions

Andrew Bennetts andrew-pythonlist at puzzling.org
Tue Mar 18 07:32:11 EST 2003


On Tue, Mar 18, 2003 at 03:30:43PM +1200, Greg Ewing (using news.cis.dfn.de) wrote:
> Andrew Bennetts wrote:
> >But from which would you expect it to resume?  Just before the exception 
> >was
> >raised?  Just after?  What about try/except blocks?  What if the exception
> >was raised inside a function called by a generator?  What about an 
> >exception
> >thrown by a generator that your generator calls?
> 
> It seems to me that what Mr. Evans wants is some way for
> a generator to cause an exception to be raised in its
> caller, without having to propagate the exception up
> through its own stack frame first.
> 
> Suppose there were a hypothetical "yield raise" statement
> which did this, then he could write

[snip]

> As for how *useful* such a thing would be, I don't know.
> I won't be leaping up to write a PEP, though...

Me either.  I suspect simply returning an Exception instance and letting the
caller do an isinstance check for Exceptions is all that's really needed,
and that's already catered for.

-Andrew.






More information about the Python-list mailing list