Here is another gen.throw() exception chain example similar to the examples in issue 29587: https://bugs.python.org/issue29587
def f():
yield
def g():
try:
raise RuntimeError('a')
except Exception as exc:
print(f'handling: {exc!r}')
yield from f()
def h():
try:
raise RuntimeError('b')
except Exception as exc:
print(f'handling: {exc!r}')
yield from g()
gen = h()
gen.send(None)
gen.throw(ValueError)
Output:
handling: RuntimeError('b')
handling: RuntimeError('a')
Traceback (most recent call last):
File "/.../test.py", line 13, in h
raise RuntimeError('b')
RuntimeError: b
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/.../test.py", line 20, in <module>
gen.throw(ValueError)
File "/.../test.py", line 16, in h
yield from g()
File "/.../test.py", line 9, in g
yield from f()
File "/.../test.py", line 2, in f
yield
ValueError
The issue is that "RuntimeError: a" is skipped. It should also appear in the exception chain.
I believe this has the same root cause as issue 29590: https://bugs.python.org/issue29590
|