Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-17188: DOC: Document 'from None' in raise statement #1671

Merged
merged 3 commits into from
May 20, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bpo-17188: DOC: Document raise 'from None'
  • Loading branch information
csabella committed May 20, 2017
commit c6aaa33be720adeaee23d2309d0d78fa9b61cace
22 changes: 20 additions & 2 deletions Doc/reference/simple_stmts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ printed::
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
ZeroDivisionError: int division or modulo by zero
ZeroDivisionError: division by zero

The above exception was the direct cause of the following exception:

Expand All @@ -606,17 +606,35 @@ attached as the new exception's :attr:`__context__` attribute::
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
ZeroDivisionError: int division or modulo by zero
ZeroDivisionError: division by zero

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<stdin>", line 4, in <module>
RuntimeError: Something bad happened

Exception chaining can be explicitly suppressed by specifying :const:`None` in
the ``from`` clause::

>>> try:
... print(1 / 0)
... except:
... raise RuntimeError("Something bad happened") from None
...
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
RuntimeError: Something bad happened

Additional information on exceptions can be found in section :ref:`exceptions`,
and information about handling exceptions is in section :ref:`try`.

.. versionchanged:: 3.3
:const:`None` is now permitted as ``Y`` in ``raise X from Y``

.. versionadded:: 3.3
The ``__suppress_context__`` attribute to suppress automatic display of the
exception context

.. _break:

Expand Down