@@ -460,12 +460,46 @@ Querying the error indicator
460460 }
461461
462462
463- .. c :function :: void PyErr_GetExcInfo (PyObject **ptype, PyObject **pvalue, PyObject **ptraceback)
463+ .. c :function :: PyObject* PyErr_GetHandledException (void)
464+
465+ Retrieve the active exception instance, as would be returned by :func:`sys.exception`.
466+ This refers to an exception that was *already caught*, not to an exception that was
467+ freshly raised. Returns a new reference to the exception or ``NULL``.
468+ Does not modify the interpreter's exception state.
469+
470+ .. note::
471+
472+ This function is not normally used by code that wants to handle exceptions.
473+ Rather, it can be used when code needs to save and restore the exception
474+ state temporarily. Use :c:func:`PyErr_SetHandledException` to restore or
475+ clear the exception state.
476+
477+ .. versionadded:: 3.11
464478
465- Retrieve the exception info, as known from ``sys.exc_info() ``. This refers
479+ .. c:function:: void PyErr_SetHandledException(PyObject *exc)
480+
481+ Set the active exception, as known from ``sys.exception() ``. This refers
466482 to an exception that was *already caught *, not to an exception that was
467- freshly raised. Returns new references for the three objects, any of which
468- may be ``NULL ``. Does not modify the exception info state.
483+ freshly raised.
484+ To clear the exception state, pass ``NULL ``.
485+
486+ .. note ::
487+
488+ This function is not normally used by code that wants to handle exceptions.
489+ Rather, it can be used when code needs to save and restore the exception
490+ state temporarily. Use :c:func: `PyErr_GetHandledException ` to get the exception
491+ state.
492+
493+ .. versionadded :: 3.11
494+
495+ .. c :function :: void PyErr_GetExcInfo (PyObject **ptype, PyObject **pvalue, PyObject **ptraceback)
496+
497+ Retrieve the old-style representation of the exception info, as known from
498+ :func: `sys.exc_info `. This refers to an exception that was *already caught *,
499+ not to an exception that was freshly raised. Returns new references for the
500+ three objects, any of which may be ``NULL ``. Does not modify the exception
501+ info state. This function is kept for backwards compatibility. Prefer using
502+ :c:func: `PyErr_GetHandledException `.
469503
470504 .. note ::
471505
@@ -483,6 +517,8 @@ Querying the error indicator
483517 to an exception that was *already caught *, not to an exception that was
484518 freshly raised. This function steals the references of the arguments.
485519 To clear the exception state, pass ``NULL `` for all three arguments.
520+ This function is kept for backwards compatibility. Prefer using
521+ :c:func: `PyErr_SetHandledException `.
486522
487523 .. note ::
488524
0 commit comments