[issue25612] nested try..excepts don't work correctly for generators
Serhiy Storchaka
report at bugs.python.org
Wed Oct 11 04:31:28 EDT 2017
Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:
I tried the following code:
def g():
yield 1
raise
yield 2
i = g()
try:
1/0
except:
next(i)
next(i)
Currently it raises:
Traceback (most recent call last):
File "<stdin>", line 5, in <module>
File "<stdin>", line 2, in <module>
ZeroDivisionError: division by zero
With PR 1773 applied it raises:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
ZeroDivisionError: division by zero
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 5, in <module>
File "<stdin>", line 3, in g
RuntimeError: No active exception to reraise
And this looks more correct.
But if replace raise with print(sys.exc_info()) the patched and unpatched interpreters both print:
(<class 'ZeroDivisionError'>, ZeroDivisionError('division by zero',), <traceback object at 0x7f61d9ed1448>)
Is it correct that sys.exc_info() return an exception while raise can't reraise it?
----------
versions: +Python 3.7 -Python 3.4, Python 3.5
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue25612>
_______________________________________
More information about the Python-bugs-list
mailing list