10000 bpo-42179: Doc/tutorial: Remove mention of __cause__ by methane · Pull Request #23162 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content
8000

bpo-42179: Doc/tutorial: Remove mention of __cause__ #23162

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

Merged
merged 3 commits into from
Nov 6, 2020
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-37826: Doc/tutorial: Remove mention to __cause__
  • Loading branch information
methane committed Nov 5, 2020
commit c704d939b0809d84d664807135df7de6cc645ee4
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
0