This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Raising exceptions from finally works better than advertised in the documentation
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, python-dev, ssegvic
Priority: normal Keywords:

Created on 2012-01-03 22:13 by ssegvic, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg150544 - (view) Author: Sinisa Segvic (ssegvic) Date: 2012-01-03 22:13
Hi,

The documentation says:
"""
If the finally clause raises another exception (...) the saved exception is lost. 
"""

This does not appear to be true. 
In the example below the backtrace shows both exceptions.

>>> import math
>>> try:
...   1/0
... finally:
...   math.sqrt(-1)
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
ZeroDivisionError: division by zero

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
ValueError: math domain error

Cheers,

Siniša
msg150546 - (view) Author: Sinisa Segvic (ssegvic) Date: 2012-01-03 22:24
Link to the documentation:
http://docs.python.org/py3k/reference/compound_stmts.html#id2
msg150547 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-01-03 22:31
New changeset c39fbb24b3f4 by Benjamin Peterson in branch '3.2':
exception support is correct now (closes #13705)
http://hg.python.org/cpython/rev/c39fbb24b3f4
History
Date User Action Args
2022-04-11 14:57:25adminsetgithub: 57914
2012-01-03 22:31:00python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg150547

resolution: fixed
stage: resolved
2012-01-03 22:24:03ssegvicsetmessages: + msg150546
2012-01-03 22:13:08ssegviccreate