◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
44 changes: 40 additions & 4 deletions Doc/c-api/exceptions.rst
Original file line number Diff line number Diff line change
@@ -460,12 +460,46 @@ Querying the error indicator
}


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

Retrieve the exception info, as known from ``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.

.. note::

Expand All @@ -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.

.. note::

Expand Down
2 changes: 2 additions & 0 deletions Doc/data/stable_abi.dat
17 changes: 5 additions & 12 deletions Doc/library/sys.rst
Original file line number Diff line number Diff line change
@@ -381,19 +381,12 @@ always available.

.. function:: exception()

This function returns the exception instance that is currently being
handled. This exception is specific both to the current thread and
to the current stack frame. If the current stack frame is not handling
an exception, the exception is taken from the calling stack frame, or its
caller, and so on until a stack frame is found that is handling an
exception. Here, "handling an exception" is defined as "executing an
except clause." For any stack frame, only the exception being currently
handled is accessible.

.. index:: object: traceback

If no exception is being handled anywhere on the stack, ``None`` is
returned.

.. versionadded:: 3.11

Expand Down
8 changes: 8 additions & 0 deletions Doc/whatsnew/3.11.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,14 @@ New Features
:c:func:`PyFrame_GetBuiltins`, :c:func:`PyFrame_GetGenerator`,
:c:func:`PyFrame_GetGlobals`, :c:func:`PyFrame_GetLasti`.

Porting to Python 3.11
----------------------

Expand Down
4 changes: 4 additions & 0 deletions Include/pyerrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ PyAPI_FUNC(PyObject *) PyErr_Occurred(void);
PyAPI_FUNC(void) PyErr_Clear(void);
PyAPI_FUNC(void) PyErr_Fetch(PyObject **, PyObject **, PyObject **);
PyAPI_FUNC(void) PyErr_Restore(PyObject *, PyObject *, PyObject *);
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
PyAPI_FUNC(void) PyErr_GetExcInfo(PyObject **, PyObject **, PyObject **);
PyAPI_FUNC(void) PyErr_SetExcInfo(PyObject *, PyObject *, PyObject *);
Expand Down
22 changes: 22 additions & 0 deletions Lib/test/test_capi.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,28 @@ def test_no_FatalError_infinite_loop(self):
def test_memoryview_from_NULL_pointer(self):
self.assertRaises(ValueError, _testcapi.make_memoryview_from_NULL_pointer)

def test_exc_info(self):
raised_exception = ValueError("5")
new_exc = TypeError("TEST")
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_stable_abi_ctypes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
5 changes: 5 additions & 0 deletions Misc/stable_abi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2253,3 +2253,8 @@ function PyMemoryView_FromBuffer

data Py_Version
added 3.11
2 changes: 2 additions & 0 deletions PC/python3dll.c
Toggle all file notes Toggle all file annotations