PEP 765: Disallow return/break/continue that exit a finally block

Oddly enough, that one does not suppress the original exception. Instead it adds a new one to the chain:

>>> z = 0
>>> def f():
...     try:
...         x = 1/z
...     finally:
...         raise NameError()
...
>>> f()
Traceback (most recent call last):
  ...
ZeroDivisionError: division by zero

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
    ...
NameError
2 Likes