Fix description of behaviour of an exception class in 'from' clause (GH-24303)

This commit is contained in:
Mark Dickinson 2021-04-11 09:33:59 +01:00 committed by GitHub
parent dfb45323ce
commit 79650d0118
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 4 deletions

View File

@ -591,10 +591,13 @@ instance, with its traceback set to its argument), like so::
__context__ (exception attribute)
The ``from`` clause is used for exception chaining: if given, the second
*expression* must be another exception class or instance, which will then be
attached to the raised exception as the :attr:`__cause__` attribute (which is
writable). If the raised exception is not handled, both exceptions will be
printed::
*expression* must be another exception class or instance. If the second
expression is an exception instance, it will be attached to the raised
exception as the :attr:`__cause__` attribute (which is writable). If the
expression is an exception class, the class will be instantiated and the
resulting exception instance will be attached to the raised exception as the
:attr:`__cause__` attribute. If the raised exception is not handled, both
exceptions will be printed::
>>> try:
... print(1 / 0)