[New-bugs-announce] [issue40694] gen.throw() with multiple yield froms skips intermediate exceptions

Chris Jerdonek report at bugs.python.org
Wed May 20 00:47:05 EDT 2020


New submission from Chris Jerdonek <chris.jerdonek at gmail.com>:

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

----------
components: Interpreter Core
messages: 369416
nosy: chris.jerdonek
priority: normal
severity: normal
status: open
title: gen.throw() with multiple yield froms skips intermediate exceptions
versions: Python 3.10

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40694>
_______________________________________


More information about the New-bugs-announce mailing list