From c704d939b0809d84d664807135df7de6cc645ee4 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Thu, 5 Nov 2020 18:04:06 +0900 Subject: [PATCH 1/3] bpo-37826: Doc/tutorial: Remove mention to __cause__ --- Doc/tutorial/errors.rst | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Doc/tutorial/errors.rst b/Doc/tutorial/errors.rst index 0ce96466e8c286..217e7f8841a262 100644 --- a/Doc/tutorial/errors.rst +++ b/Doc/tutorial/errors.rst @@ -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:: @@ -299,10 +299,9 @@ This can be useful when you are transforming exceptions. For example:: File "", line 4, in 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 +disabled by using ``from None`` idiom: >>> try: ... open('database.sqlite') @@ -313,6 +312,8 @@ can be disabled by using ``from None`` idiom: File "", line 4, in RuntimeError +For more information about chaining mechanics, see :ref:`bltin-exceptions`. + .. _tut-userexceptions: From 7508f69873ec0611e3b106578aa365804764e75b Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Fri, 6 Nov 2020 08:01:23 +0900 Subject: [PATCH 2/3] fixup --- Doc/tutorial/errors.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/tutorial/errors.rst b/Doc/tutorial/errors.rst index 217e7f8841a262..28b1f14ed8b81b 100644 --- a/Doc/tutorial/errors.rst +++ b/Doc/tutorial/errors.rst @@ -275,13 +275,13 @@ Exception Chaining The :keyword:`raise` statement allows an optional :keyword:`from` which enables chaining exceptions. For example:: - # exc must be ether exception instance or None. + # 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() @@ -300,8 +300,8 @@ This can be useful when you are transforming exceptions. For example:: RuntimeError 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: +:keyword:`except` section or :keyword:`finally` section. Exception chaining can +be disabled by using ``from None`` idiom: >>> try: ... open('database.sqlite') From b43dfa6fdf04d0e416d3c3e0b308f162f04d562c Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Fri, 6 Nov 2020 08:12:41 +0900 Subject: [PATCH 3/3] fixup --- Doc/tutorial/errors.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/tutorial/errors.rst b/Doc/tutorial/errors.rst index 28b1f14ed8b81b..efe44da3043c5e 100644 --- a/Doc/tutorial/errors.rst +++ b/Doc/tutorial/errors.rst @@ -297,11 +297,11 @@ This can be useful when you are transforming exceptions. For example:: Traceback (most recent call last): File "", line 4, in - RuntimeError + RuntimeError: Failed to open database Exception chaining happens automatically when an exception is raised inside an -:keyword:`except` section or :keyword:`finally` section. Exception chaining can -be disabled by using ``from None`` idiom: +:keyword:`except` or :keyword:`finally` section. Exception chaining can be +disabled by using ``from None`` idiom: >>> try: ... open('database.sqlite')