mirror of
https://github.com/python/cpython.git
synced 2025-09-29 19:56:59 +00:00
bpo-17188: DOC: Document 'from None' in raise statement (GH-1671) (GH-1867)
Original patch by Dennis Mårtensson.
(cherry picked from commit 763557eac0
)
This commit is contained in:
parent
03c7600982
commit
00b381b9a7
2 changed files with 21 additions and 2 deletions
|
@ -587,7 +587,7 @@ printed::
|
||||||
...
|
...
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
File "<stdin>", line 2, in <module>
|
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:
|
The above exception was the direct cause of the following exception:
|
||||||
|
|
||||||
|
@ -606,7 +606,7 @@ attached as the new exception's :attr:`__context__` attribute::
|
||||||
...
|
...
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
File "<stdin>", line 2, in <module>
|
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:
|
During handling of the above exception, another exception occurred:
|
||||||
|
|
||||||
|
@ -614,9 +614,27 @@ attached as the new exception's :attr:`__context__` attribute::
|
||||||
File "<stdin>", line 4, in <module>
|
File "<stdin>", line 4, in <module>
|
||||||
RuntimeError: Something bad happened
|
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`,
|
Additional information on exceptions can be found in section :ref:`exceptions`,
|
||||||
and information about handling exceptions is in section :ref:`try`.
|
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:
|
.. _break:
|
||||||
|
|
||||||
|
|
|
@ -963,6 +963,7 @@ David Marek
|
||||||
Doug Marien
|
Doug Marien
|
||||||
Sven Marnach
|
Sven Marnach
|
||||||
Alex Martelli
|
Alex Martelli
|
||||||
|
Dennis Mårtensson
|
||||||
Anthony Martin
|
Anthony Martin
|
||||||
Owen Martin
|
Owen Martin
|
||||||
Sidney San Martín
|
Sidney San Martín
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue