rogerbinns / apsw

Another Python SQLite wrapper
https://rogerbinns.github.io/apsw/
Other
715 stars 96 forks source link

Update exception handling #480

Closed rogerbinns closed 9 months ago

rogerbinns commented 10 months ago

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:

Add PyErr_GetRaisedException() and PyErr_SetRaisedException() for saving and restoring the current exception. These functions return and accept a single exception object, rather than the triple arguments of the now-deprecated PyErr_Fetch() and PyErr_Restore(). This is less error prone and a bit more efficient. (Contributed by Mark Shannon in gh-101578.)

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.)

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 */
rogerbinns commented 9 months ago

This is now complete. There weren't really any opportunities for exception chaining because multiple exceptions are really independent of each other