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

gh-101578: Amend exception docs #102057

Merged
merged 3 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions Doc/c-api/exceptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -438,17 +438,18 @@ Querying the error indicator

.. c:function:: void PyErr_Fetch(PyObject **ptype, PyObject **pvalue, PyObject **ptraceback)

As of 3.12, this function is deprecated. Use :c:func:`PyErr_GetRaisedException` instead.

Retrieve the error indicator into three variables whose addresses are passed.
If the error indicator is not set, set all three variables to ``NULL``. If it is
set, it will be cleared and you own a reference to each object retrieved. The
value and traceback object may be ``NULL`` even when the type object is not.

.. note::

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.::
This function is normally only used by legacy code that needs to catch
exceptions or by code that needs to save and restore the error indicator
temporarily.
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved

For example::

{
PyObject *type, *value, *traceback;
Expand All @@ -461,10 +462,10 @@ Querying the error indicator

.. deprecated:: 3.12

Use :c:func:`PyErr_GetRaisedException` instead.
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved

.. c:function:: void PyErr_Restore(PyObject *type, PyObject *value, PyObject *traceback)

As of 3.12, this function is deprecated. Use :c:func:`PyErr_SetRaisedException` instead.
.. c:function:: void PyErr_Restore(PyObject *type, PyObject *value, PyObject *traceback)

Set the error indicator from the three objects. If the error indicator is
already set, it is cleared first. If the objects are ``NULL``, the error
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -478,18 +479,16 @@ Querying the error indicator

.. note::

This function is normally only used by code that needs to save and restore the
error indicator temporarily. Use :c:func:`PyErr_Fetch` to save the current
error indicator.
This function is normally only used by legacy code that needs to
save and restore the error indicator temporarily.
Use :c:func:`PyErr_Fetch` to save the current error indicator.

.. deprecated:: 3.12

Use :c:func:`PyErr_SetRaisedException` instead.
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved

.. c:function:: void PyErr_NormalizeException(PyObject **exc, PyObject **val, PyObject **tb)

As of 3.12, this function is deprecated.
Use :c:func:`PyErr_GetRaisedException` instead of :c:func:`PyErr_Fetch` to avoid
any possible de-normalization.
.. c:function:: void PyErr_NormalizeException(PyObject **exc, PyObject **val, PyObject **tb)

Under certain circumstances, the values returned by :c:func:`PyErr_Fetch` below
can be "unnormalized", meaning that ``*exc`` is a class object but ``*val`` is
Expand All @@ -509,6 +508,9 @@ Querying the error indicator

.. deprecated:: 3.12

Use :c:func:`PyErr_GetRaisedException` instead,
to avoid any possible de-normalization.
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved


.. c:function:: PyObject* PyErr_GetHandledException(void)

Expand Down Expand Up @@ -756,14 +758,12 @@ Exception Objects

.. c:function:: PyObject* PyException_GetArgs(PyObject *ex)

Return args of the given exception as a new reference,
as accessible from Python through :attr:`args`.
Return :attr:`~BaseException.args` of exception *ex*.


.. c:function:: void PyException_SetArgs(PyObject *ex, PyObject *args)

Set the args of the given exception,
as accessible from Python through :attr:`args`.
Set :attr:`~BaseException.args` of exception *ex* to *args*:


.. _unicodeexceptions:
Expand Down
2 changes: 2 additions & 0 deletions Doc/data/refcounts.dat
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,8 @@ PyEval_EvalFrameEx:int:throwflag::
PyEval_MergeCompilerFlags:int:::
PyEval_MergeCompilerFlags:PyCompilerFlags*:cf::

PyException_GetArgs:PyObject*::+1:

PyException_GetCause:PyObject*::+1:
PyException_GetCause:PyObject*:ex:0:

Expand Down