Skip to content
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
15 changes: 8 additions & 7 deletions Doc/tutorial/errors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,10 @@ 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 ether exception instance or None.
raise RuntimeError from exc

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

Expand All @@ -299,10 +299,9 @@ This can be useful when you are transforming exceptions. For example::
File "<stdin>", line 4, in <module>
RuntimeError

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
exception handler or :keyword:`finally` section. Exception chaining can be
Copy link
Member

@merwok merwok Nov 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of adding: an exception handler (an :keyboard:`except` block)

Copy link
Contributor

@willingc willingc Nov 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or possibly a :keyboard: `try` block's exception handler

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used a parenthetical on purpose to signify that «exception handler» == «except block» (I wrote try block by mistaked at first).
Otherwise it could be confusing what an exception handler is (is it a function you call in except? is it excepthook?)

Copy link
Member Author

@methane methane Nov 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already use :keyword:`finally` section.
How about just :keyword:`except` or :keyword:`finally` section for consistency?

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