summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGéry Ogam <gery.ogam@gmail.com>2020-12-21 13:13:08 (GMT)
committerGitHub <noreply@github.com>2020-12-21 13:13:08 (GMT)
commitd515c610c61b9a8c40c037a3dc3bfc8d67563658 (patch)
tree36c4e5f0d0d0fee97a40f3c7a058cc292f4b92d9
parent37a6d5f8027f969418fe53d0a73a21003a8e370d (diff)
downloadcpython-d515c610c61b9a8c40c037a3dc3bfc8d67563658.zip
cpython-d515c610c61b9a8c40c037a3dc3bfc8d67563658.tar.gz
cpython-d515c610c61b9a8c40c037a3dc3bfc8d67563658.tar.bz2
bpo-35790: Correct the description of sys.exc_info() and add a code example (GH-11625)
-rw-r--r--Doc/reference/compound_stmts.rst24
1 files changed, 21 insertions, 3 deletions
diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst
index 8da74c7..5bba3ee 100644
--- a/Doc/reference/compound_stmts.rst
+++ b/Doc/reference/compound_stmts.rst
@@ -302,9 +302,27 @@ Before an except clause's suite is executed, details about the exception are
stored in the :mod:`sys` module and can be accessed via :func:`sys.exc_info`.
:func:`sys.exc_info` returns a 3-tuple consisting of the exception class, the
exception instance and a traceback object (see section :ref:`types`) identifying
-the point in the program where the exception occurred. :func:`sys.exc_info`
-values are restored to their previous values (before the call) when returning
-from a function that handled an exception.
+the point in the program where the exception occurred. The details about the
+exception accessed via :func:`sys.exc_info` are restored to their previous values
+when leaving an exception handler::
+
+ >>> print(sys.exc_info())
+ (None, None, None)
+ >>> try:
+ ... raise TypeError
+ ... except:
+ ... print(sys.exc_info())
+ ... try:
+ ... raise ValueError
+ ... except:
+ ... print(sys.exc_info())
+ ... print(sys.exc_info())
+ ...
+ (<class 'TypeError'>, TypeError(), <traceback object at 0x10efad080>)
+ (<class 'ValueError'>, ValueError(), <traceback object at 0x10efad040>)
+ (<class 'TypeError'>, TypeError(), <traceback object at 0x10efad080>)
+ >>> print(sys.exc_info())
+ (None, None, None)
.. index::
keyword: else