summaryrefslogtreecommitdiffstats
path: root/Doc/c-api
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2022-04-15 18:57:47 (GMT)
committerGitHub <noreply@github.com>2022-04-15 18:57:47 (GMT)
commit5d421d7342fc0d278c129c05bea7028430e94a4e (patch)
treec5bb38c41d86c6289dfcb1f7937f2df07305f4d8 /Doc/c-api
parentc06a4ffe818feddef3b5083d9746a1c0b82c84ab (diff)
downloadcpython-5d421d7342fc0d278c129c05bea7028430e94a4e.zip
cpython-5d421d7342fc0d278c129c05bea7028430e94a4e.tar.gz
cpython-5d421d7342fc0d278c129c05bea7028430e94a4e.tar.bz2
gh-90501: Add PyErr_GetHandledException and PyErr_SetHandledException (GH-30531)
Diffstat (limited to 'Doc/c-api')
-rw-r--r--Doc/c-api/exceptions.rst44
1 files changed, 40 insertions, 4 deletions
diff --git a/Doc/c-api/exceptions.rst b/Doc/c-api/exceptions.rst
index a5a93d0..7bfeca5 100644
--- a/Doc/c-api/exceptions.rst
+++ b/Doc/c-api/exceptions.rst
@@ -460,12 +460,46 @@ Querying the error indicator
}
-.. c:function:: void PyErr_GetExcInfo(PyObject **ptype, PyObject **pvalue, PyObject **ptraceback)
+.. c:function:: PyObject* PyErr_GetHandledException(void)
+
+ Retrieve the active exception instance, as would be returned by :func:`sys.exception`.
+ This refers to an exception that was *already caught*, not to an exception that was
+ freshly raised. Returns a new reference to the exception or ``NULL``.
+ Does not modify the interpreter's exception state.
+
+ .. note::
+
+ This function is not normally used by code that wants to handle exceptions.
+ Rather, it can be used when code needs to save and restore the exception
+ state temporarily. Use :c:func:`PyErr_SetHandledException` to restore or
+ clear the exception state.
+
+ .. versionadded:: 3.11
- Retrieve the exception info, as known from ``sys.exc_info()``. This refers
+.. c:function:: void PyErr_SetHandledException(PyObject *exc)
+
+ Set the active exception, as known from ``sys.exception()``. This refers
to an exception that was *already caught*, not to an exception that was
- freshly raised. Returns new references for the three objects, any of which
- may be ``NULL``. Does not modify the exception info state.
+ freshly raised.
+ To clear the exception state, pass ``NULL``.
+
+ .. note::
+
+ This function is not normally used by code that wants to handle exceptions.
+ Rather, it can be used when code needs to save and restore the exception
+ state temporarily. Use :c:func:`PyErr_GetHandledException` to get the exception
+ state.
+
+ .. versionadded:: 3.11
+
+.. c:function:: void PyErr_GetExcInfo(PyObject **ptype, PyObject **pvalue, PyObject **ptraceback)
+
+ Retrieve the old-style representation of the exception info, as known from
+ :func:`sys.exc_info`. This refers to an exception that was *already caught*,
+ not to an exception that was freshly raised. Returns new references for the
+ three objects, any of which may be ``NULL``. Does not modify the exception
+ info state. This function is kept for backwards compatibility. Prefer using
+ :c:func:`PyErr_GetHandledException`.
.. note::
@@ -483,6 +517,8 @@ Querying the error indicator
to an exception that was *already caught*, not to an exception that was
freshly raised. This function steals the references of the arguments.
To clear the exception state, pass ``NULL`` for all three arguments.
+ This function is kept for backwards compatibility. Prefer using
+ :c:func:`PyErr_SetHandledException`.
.. note::