@@ -273,15 +273,15 @@ Exception Chaining
273
273
==================
274
274
275
275
The :keyword: `raise ` statement allows an optional :keyword: `from ` which enables
276
- chaining exceptions by setting the ``__cause__ `` attribute of the raised
277
- exception. For example::
276
+ chaining exceptions. For example::
278
277
279
- raise RuntimeError from OSError
278
+ # exc must be exception instance or None.
279
+ raise RuntimeError from exc
280
280
281
281
This can be useful when you are transforming exceptions. For example::
282
282
283
283
>>> def func():
284
- ... raise IOError
284
+ ... raise IOError
285
285
...
286
286
>>> try:
287
287
... func()
@@ -297,12 +297,11 @@ This can be useful when you are transforming exceptions. For example::
297
297
<BLANKLINE>
298
298
Traceback (most recent call last):
299
299
File "<stdin>", line 4, in <module>
300
- RuntimeError
300
+ RuntimeError: Failed to open database
301
301
302
- The expression following the :keyword: `from ` must be either an exception or
303
- ``None ``. Exception chaining happens automatically when an exception is raised
304
- inside an exception handler or :keyword: `finally ` section. Exception chaining
305
- can be disabled by using ``from None `` idiom:
302
+ Exception chaining happens automatically when an exception is raised inside an
303
+ :keyword: `except ` or :keyword: `finally ` section. Exception chaining can be
304
+ disabled by using ``from None `` idiom:
306
305
307
306
>>> try :
308
307
... open (' database.sqlite' )
@@ -313,6 +312,8 @@ can be disabled by using ``from None`` idiom:
313
312
File "<stdin>", line 4, in <module>
314
313
RuntimeError
315
314
315
+ For more information about chaining mechanics, see :ref: `bltin-exceptions `.
316
+
316
317
317
318
.. _tut-userexceptions :
318
319
0 commit comments