summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErlend E. Aasland <erlend.aasland@protonmail.com>2023-02-19 20:22:29 (GMT)
committerGitHub <noreply@github.com>2023-02-19 20:22:29 (GMT)
commit60bbed7f174e481d3fc69984430a4667951678b3 (patch)
tree417f5973ef9884d00d179f896997a38de6fa795c
parent3b264df470c82d77f5b01c6f9d1d7173d1cb9597 (diff)
downloadcpython-60bbed7f174e481d3fc69984430a4667951678b3.zip
cpython-60bbed7f174e481d3fc69984430a4667951678b3.tar.gz
cpython-60bbed7f174e481d3fc69984430a4667951678b3.tar.bz2
gh-101578: Amend PyErr_{Set,Get}RaisedException docs (#101962)
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
-rw-r--r--Doc/c-api/exceptions.rst49
-rw-r--r--Doc/data/refcounts.dat3
2 files changed, 20 insertions, 32 deletions
diff --git a/Doc/c-api/exceptions.rst b/Doc/c-api/exceptions.rst
index de9b15e..e735f8d 100644
--- a/Doc/c-api/exceptions.rst
+++ b/Doc/c-api/exceptions.rst
@@ -402,51 +402,36 @@ Querying the error indicator
.. c:function:: PyObject *PyErr_GetRaisedException(void)
- Returns the exception currently being raised, clearing the exception at
- the same time. Do not confuse this with the exception currently being
- handled which can be accessed with :c:func:`PyErr_GetHandledException`.
+ Return the exception currently being raised, clearing the error indicator at
+ the same time.
- .. note::
+ This function is used by code that needs to catch exceptions,
+ or code that needs to save and restore the error indicator temporarily.
- This function is normally only used by code that needs to catch exceptions or
- by code that needs to save and restore the error indicator temporarily, e.g.::
+ For example::
- {
- PyObject *exc = PyErr_GetRaisedException();
+ {
+ PyObject *exc = PyErr_GetRaisedException();
- /* ... code that might produce other errors ... */
+ /* ... code that might produce other errors ... */
- PyErr_SetRaisedException(exc);
- }
+ PyErr_SetRaisedException(exc);
+ }
+
+ .. seealso:: :c:func:`PyErr_GetHandledException`,
+ to save the exception currently being handled.
.. versionadded:: 3.12
.. c:function:: void PyErr_SetRaisedException(PyObject *exc)
- Sets the exception currently being raised ``exc``.
- If the exception is already set, it is cleared first.
-
- ``exc`` must be a valid exception.
- (Violating this rules will cause subtle problems later.)
- This call consumes a reference to the ``exc`` object: you must own a
- reference to that object before the call and after the call you no longer own
- that reference.
- (If you don't understand this, don't use this function. I warned you.)
+ Set *exc* as the exception currently being raised,
+ clearing the existing exception if one is set.
- .. note::
-
- This function is normally only used by code that needs to save and restore the
- error indicator temporarily. Use :c:func:`PyErr_GetRaisedException` to save
- the current exception, e.g.::
-
- {
- PyObject *exc = PyErr_GetRaisedException();
-
- /* ... code that might produce other errors ... */
+ .. warning::
- PyErr_SetRaisedException(exc);
- }
+ This call steals a reference to *exc*, which must be a valid exception.
.. versionadded:: 3.12
diff --git a/Doc/data/refcounts.dat b/Doc/data/refcounts.dat
index 349c4dd..ed2958f 100644
--- a/Doc/data/refcounts.dat
+++ b/Doc/data/refcounts.dat
@@ -606,6 +606,9 @@ PyErr_GetExcInfo:PyObject**:ptype:+1:
PyErr_GetExcInfo:PyObject**:pvalue:+1:
PyErr_GetExcInfo:PyObject**:ptraceback:+1:
+PyErr_GetRaisedException:PyObject*::+1:
+PyErr_SetRaisedException::::
+
PyErr_GivenExceptionMatches:int:::
PyErr_GivenExceptionMatches:PyObject*:given:0:
PyErr_GivenExceptionMatches:PyObject*:exc:0: