Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
bpo-29587: set exc.__context__ when calling gen.throw() (GH-19811)
Before this commit, if an exception was active inside a generator
when calling gen.throw(), then that exception was lost (i.e. there
was no implicit exception chaining).  This commit fixes that.
  • Loading branch information
cjerdonek committed Apr 30, 2020
commit b377e49d9c64af14ec1b3d3a2960edb2ec63dc0b
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Enable implicit exception chaining when calling :meth:`generator.throw`.
6 changes: 6 additions & 0 deletions Objects/genobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,12 @@ _gen_throw(PyGenObject *gen, int close_on_genexit,
}

PyErr_Restore(typ, val, tb);
if (gen->gi_exc_state.exc_type) {
Py_INCREF(gen->gi_exc_state.exc_type);
Py_XINCREF(gen->gi_exc_state.exc_value);
Py_XINCREF(gen->gi_exc_state.exc_traceback);
_PyErr_ChainExceptions(gen->gi_exc_state.exc_type, gen->gi_exc_state.exc_value, gen->gi_exc_state.exc_traceback);
}
return gen_send_ex(gen, Py_None, 1, 0);

failed_throw:
Expand Down