diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-01-27 10:51:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-27 10:51:06 (GMT) |
commit | 2572c670d42887e4b1d2475b8da2e9bf6e0aa558 (patch) | |
tree | 41ee8d981242df8a05064ec6948a5cb2e204c827 /Doc/library | |
parent | 1ecc98dedb7ae77c2d806a70b52dfecdac39ff5b (diff) | |
download | cpython-2572c670d42887e4b1d2475b8da2e9bf6e0aa558.zip cpython-2572c670d42887e4b1d2475b8da2e9bf6e0aa558.tar.gz cpython-2572c670d42887e4b1d2475b8da2e9bf6e0aa558.tar.bz2 |
[3.10] bpo-23556: [doc] Fix inaccuracy in documentation for raise without args. Improve tests for context in nested except handlers. (GH-29236) (GH-30953)
(cherry picked from commit 08c0ed2d9c0d01ad1a5adc0787bc75e4e90cbb85)
Co-authored-by: Kinshuk Dua <kinshukdua@gmail.com>
Automerge-Triggered-By: GH:iritkatriel
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/exceptions.rst | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst index f8a692e..2f97bb8 100644 --- a/Doc/library/exceptions.rst +++ b/Doc/library/exceptions.rst @@ -38,15 +38,14 @@ information on defining exceptions is available in the Python Tutorial under Exception context ----------------- -When raising (or re-raising) an exception in an :keyword:`except` or -:keyword:`finally` clause -:attr:`__context__` is automatically set to the last exception caught; if the -new exception is not handled the traceback that is eventually displayed will -include the originating exception(s) and the final exception. - -When raising a new exception (rather than using a bare ``raise`` to re-raise -the exception currently being handled), the implicit exception context can be -supplemented with an explicit cause by using :keyword:`from<raise>` with +When raising a new exception while another exception +is already being handled, the new exception's +:attr:`__context__` attribute is automatically set to the handled +exception. An exception may be handled when an :keyword:`except` or +:keyword:`finally` clause, or a :keyword:`with` statement, is used. + +This implicit exception context can be +supplemented with an explicit cause by using :keyword:`!from` with :keyword:`raise`:: raise new_exc from original_exc |