PEP 760 – No More Bare Excepts

Ideally if you want to intercept an exception and pass it through, you would do it will finally:

It would be nice to not have to use sys. What if we added an option to bind the exception in a finally block, as in:

try:
    raise Exception("Hello")
finally e:
    if e is not None:
        e.add_note("World")
4 Likes