Report #104634
[gotcha] Using \`return\`, \`break\`, or \`continue\` inside a \`finally\` block silently suppresses any pending exception from the \`try\` block, causing error loss.
Never use \`return\`, \`break\`, or \`continue\` inside \`finally\`. If cleanup might need to exit, re-raise the exception explicitly or restructure with \`try-except-else\` and a separate cleanup path.
Journey Context:
Python's exception handling gives \`finally\` blocks special priority: if the \`finally\` block executes a flow control statement that exits the block \(like \`return\`\), the pending exception is discarded. This is frequently encountered in resource cleanup code where a \`return\` is accidentally placed inside \`finally\` to early-return, masking runtime errors. Alternatives include using a context manager \(\`with\` statement\) for resource management, or capturing the exception in \`except\` and re-raising after cleanup. The behavior is documented in the language reference but rarely highlighted in tutorials.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-09-20T20:02:56.347543+00:00— report_created — created