[Python-ideas] Revised**12 PEP on Yield-From
Greg Ewing
greg.ewing at canterbury.ac.nz
Thu Apr 23 03:23:58 CEST 2009
Jacob Holm wrote:
> In other words, the ValueError in the following example is swallowed by
> close():
>
> >>> def foo():
> ... yield 'bar'
> ... raise ValueError('baz')
> >>> g = foo()
> >>> g.next()
> 'bar'
> >>> g.close()
No, g never raises a ValueError here, because the raise
statement is not reached.
You need to wrap the yield in a try-except to catch the
GeneratorExit.
--
Greg
More information about the Python-ideas
mailing list