2 Comments
User's avatar
Pepe Silvia's avatar

I like to highlight this example in some teaching. I further highlight that the behaviour is pre-empted by acceptance of PEP 765: https://peps.python.org/pep-0765/, which appears to be implemented in 3.14: https://docs.python.org/3.14/reference/compound_stmts.html#finally. The compiler emits a SyntaxWarning when a return, break or continue appears in a finally block.

Expand full comment
Wyrd Smythe's avatar

I knew "Finally executed" printed but I didn't realize the break cancelled the second exception. Thanks for the lesson!

Expand full comment