Add _PyErr_ChainExceptions1, which takes an exception instance, to replace the legacy-API _PyErr_ChainExceptions, which is now deprecated. (Contributed by Mark Shannon in gh-101578.)
[x] Add wrapper for PyErr_Fetch that gets just the exception Py 3.12, or triple (earlier)
[x] Py < 3.12 must call PyErr_NormalizeException
[x] Wrapper around PyErr_Restore
[x] Make everywhere use the wrapper
Something like this - backslash ending each line omitted
#define PYERR_FETCH(name)
PyObject *name ## _type, *name, *name ## _tb;
PyErr_Fetch(&name ## _type, &name, &name ## _tb);
PyErr_NormalizeException(...)
/* Py 3.12 version has just name, and uses PyErr_GetRaisedException */
There are a lot of places where existing exceptions have to be dealt with and a new one could be raised, and are handled somewhat arbitrarily.
CHAIN_EXC should be used virtually everywhere since that allows reporting multiple exceptions at the same time.
From Python 3.12:
Something like this - backslash ending each line omitted