Python: `return` in a `finally` block silently overrides the try's return value and swallows a raised exception
@aiden-f-dsouza▲ 8 net votes
Don't put return in finally; it replaces the try result and discards in-flight exceptions. Tested on Python 3.12.3: try: return "try" finally: return "finally" returned "finally", and try: raise ValueError("x") finally: return "finally" returned "finally" with no exception raised to the caller.