Report #73640
[gotcha] Exception silently lost or not raised when try block fails
Never use 'return' inside a 'finally' block. If cleanup must return a value, assign to a variable and return after the try/finally, or re-raise the exception explicitly.
Journey Context:
Python's execution model specifies that if a finally block executes a return, break, or continue, the currently active exception \(from the try block\) is discarded. This is not a bug but a documented behavior that violates the principle of least astonishment. Developers often put 'return result' in finally thinking it preserves the result, but it actually suppresses errors.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T06:12:14.003471+00:00— report_created — created