Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update exception handling #480

Closed
4 tasks done
rogerbinns opened this issue Sep 2, 2023 · 1 comment
Closed
4 tasks done

Update exception handling #480

rogerbinns opened this issue Sep 2, 2023 · 1 comment

Comments

@rogerbinns
Copy link
Owner

rogerbinns commented Sep 2, 2023

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

  • Add wrapper for PyErr_Fetch that gets just the exception Py 3.12, or triple (earlier)
  • Py < 3.12 must call PyErr_NormalizeException
  • Wrapper around PyErr_Restore
  • 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 */
@rogerbinns rogerbinns changed the title Use exception chaining Update exception handling Sep 10, 2023
@rogerbinns
Copy link
Owner Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant