gh-90501: Add PyErr_GetHandledException and PyErr_SetHandledException by iritkatriel · Pull Request #30531 · python/cpython (original) (raw)

Would it be possible to use the same wording in the documentation of functions added by this PR, in PyErr_GetExcInfo() and in sys.exception() documentation? My remark is about "the exception instance that is currently being handled" in sys.exception() doc: https://docs.python.org/dev/library/sys.html#sys.exception

sys.exception is in python space, where you don't have access to any other exception so I think the c-level wording might just add confusion. I agree though that the current wording is not great, in particular I'm not sure we need to talk about the frame stack. How about I reword the sys.exception() doc like this:

This function, when called while an exception handler (such as an ``except`` or ``except*`` clause) is executing, returns the exception instance that was caught by this handler. When exception handlers are nested within one another, only the exception handled by the innermost handler is accessible.

If no exception handler is executing, this function returns None.

Maybe add also a link from PyErr_GetExcInfo() to PyErr_GetActiveException() in the doc.

Sure.