[issue23188] Provide a C helper function to chain raised (but not yet caught) exceptions
Eric Snow
report at bugs.python.org
Tue May 22 12:24:32 EDT 2018
Eric Snow <ericsnowcurrently at gmail.com> added the comment:
FTR, see PEP 490 ("Chain exceptions at C level") which proposed implicitly chaining exceptions in the PyErr_* API.
While that PEP was rejected (not all exceptions should be chained), it does make a good point about the clunkiness of using _PyErr_ChainExceptions():
PyObject *exc, *val, *tb;
PyErr_Fetch(&exc, &val, &tb);
PyErr_Format(ZipImportError, "can't open Zip file: %R", archive);
_PyErr_ChainExceptions(exc, val, tb);
So if we are going to add a public helper function, let's consider adding one that simplifies usage. For instance, how about one that indicates the next exception set should chain:
PyErr_ChainNext();
PyErr_Format(ZipImportError, "can't open Zip file: %R", archive);
Or perhaps we should revive PEP 490 with an opt out mechanism for the cases where we don't want chaining:
PyErr_NoChainNext();
PyErr_Format(PyExc_RuntimeError, "uh-oh");
----------
nosy: +eric.snow, vstinner
versions: +Python 3.8 -Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue23188>
_______________________________________
More information about the Python-bugs-list
mailing list