Comment 1 for bug 1764210

Revision history for this message
Ryan Harper (raharper) wrote :

My reading of the python3 docs suggests that this analysis is correct. If we issue a return, then the saved exception is discarded.

If finally is present, it specifies a ‘cleanup’ handler. The try clause is executed, including any except and else clauses. If an exception occurs in any of the clauses and is not handled, the exception is temporarily saved. The finally clause is executed. If there is a saved exception it is re-raised at the end of the finally clause. If the finally clause raises another exception, the saved exception is set as the context of the new exception. If the finally clause executes a return or break statement, the saved exception is discarded:

>>>
>>> def f():
... try:
... 1/0
... finally:
... return 42
...
>>> f()
42

https://docs.python.org/3/reference/compound_stmts.html#try