This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: gen.throw() with multiple yield froms skips intermediate exceptions
Type: Stage:
Components: Interpreter Core Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: chris.jerdonek
Priority: normal Keywords:

Created on 2020-05-20 04:47 by chris.jerdonek, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg369416 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2020-05-20 04:47
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
History
Date User Action Args
2022-04-11 14:59:31adminsetgithub: 84871
2020-05-20 04:47:05chris.jerdonekcreate