A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2010-August/102609.html below:

[Python-Dev] Exception chaining and generator finalisation

[Python-Dev] Exception chaining and generator finalisationAntoine Pitrou solipsis at pitrou.net
Sun Aug 1 05:46:46 CEST 2010
On Sun, 01 Aug 2010 13:01:32 +1200
Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> While updating my yield-from impementation for Python
> 3.1.2, I came across a quirk in the way that the new
> exception chaining feature interacts with generators.
> 
> If you close() a generator, and it raises an exception
> inside a finally clause, you get a double-barrelled
> traceback that first reports a GeneratorExit, then
> "During handling of the above exception, another
> exception occurred", followed by the traceback for
> the exception raised by the generator.

It only happens if you call close() explicitly:

>>> def g():
...   try: yield 1
...   finally: 1/0
... 
>>> gi = g()
>>> next(gi)
1
>>> del gi
Exception ZeroDivisionError: ZeroDivisionError('division by zero',) in
<generator object g at 0x7fe50351ddc0> ignored
>>> gi = g()
>>> next(gi)
1
>>> next(gi)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in g
ZeroDivisionError: division by zero
>>> 


Regards

Antoine.


More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4