Skip to content

Commit

Permalink
bpo-42179: Doc/tutorial: Remove mention of __cause__ (pythonGH-23162)
Browse files Browse the repository at this point in the history
  • Loading branch information
methane authored Nov 6, 2020
1 parent 91e9379 commit bde33e4
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions Doc/tutorial/errors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,15 @@ Exception Chaining
==================

The :keyword:`raise` statement allows an optional :keyword:`from` which enables
chaining exceptions by setting the ``__cause__`` attribute of the raised
exception. For example::
chaining exceptions. For example::

raise RuntimeError from OSError
# exc must be exception instance or None.
raise RuntimeError from exc

This can be useful when you are transforming exceptions. For example::

>>> def func():
... raise IOError
... raise IOError
...
>>> try:
... func()
Expand All @@ -297,12 +297,11 @@ This can be useful when you are transforming exceptions. For example::
<BLANKLINE>
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
RuntimeError
RuntimeError: Failed to open database

The expression following the :keyword:`from` must be either an exception or
``None``. Exception chaining happens automatically when an exception is raised
inside an exception handler or :keyword:`finally` section. Exception chaining
can be disabled by using ``from None`` idiom:
Exception chaining happens automatically when an exception is raised inside an
:keyword:`except` or :keyword:`finally` section. Exception chaining can be
disabled by using ``from None`` idiom:

>>> try:
... open('database.sqlite')
Expand All @@ -313,6 +312,8 @@ can be disabled by using ``from None`` idiom:
File "<stdin>", line 4, in <module>
RuntimeError

For more information about chaining mechanics, see :ref:`bltin-exceptions`.


.. _tut-userexceptions:

Expand Down

0 comments on commit bde33e4

Please sign in to comment.