diff options
Diffstat (limited to 'Doc/library/sys.rst')
-rw-r--r-- | Doc/library/sys.rst | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index 7d27c89..3b754bd 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -248,16 +248,19 @@ always available. before the program exits. The handling of such top-level exceptions can be customized by assigning another three-argument function to ``sys.excepthook``. + See also :func:`unraisablehook` which handles unraisable exceptions. + .. data:: __breakpointhook__ __displayhook__ __excepthook__ + __unraisablehook__ These objects contain the original values of ``breakpointhook``, - ``displayhook``, and ``excepthook`` at the start of the program. They are - saved so that ``breakpointhook``, ``displayhook`` and ``excepthook`` can be - restored in case they happen to get replaced with broken or alternative - objects. + ``displayhook``, ``excepthook``, and ``unraisablehook`` at the start of the + program. They are saved so that ``breakpointhook``, ``displayhook`` and + ``excepthook``, ``unraisablehook`` can be restored in case they happen to + get replaced with broken or alternative objects. .. versionadded:: 3.7 __breakpointhook__ @@ -1487,6 +1490,28 @@ always available. is suppressed and only the exception type and value are printed. +.. function:: unraisablehook(unraisable, /) + + Handle an unraisable exception. + + Called when an exception has occurred but there is no way for Python to + handle it. For example, when a destructor raises an exception or during + garbage collection (:func:`gc.collect`). + + The *unraisable* argument has the following attributes: + + * *exc_type*: Exception type. + * *exc_value*: Exception value, can be ``None``. + * *exc_traceback*: Exception traceback, can be ``None``. + * *object*: Object causing the exception, can be ``None``. + + :func:`sys.unraisablehook` can be overridden to control how unraisable + exceptions are handled. + + See also :func:`excepthook` which handles uncaught exceptions. + + .. versionadded:: 3.8 + .. data:: version A string containing the version number of the Python interpreter plus additional |