What this Python exception-handling question tests
This is a medium-difficulty question that probes your understanding of exception unwinding and control flow in Python, particularly how try, except, finally, and raise interact during stack unwinding. It's the kind of question that separates candidates who have read Python documentation from those who have internalized the runtime behaviour.
To solve problems like this, you need to trace the exact order in which code blocks execute when an exception is raised—which statements run before unwinding, which run during cleanup, and how re-raising or new exceptions affect the flow. The answer hinges on understanding that finally blocks always execute, but their timing relative to exception propagation matters.
- Try-except-finally execution order
- Exception propagation and stack unwinding
- When finally blocks run relative to exception handling
- Re-raising and chained exceptions