[Python-ideas] Make return inside a finally a SyntaxError

Terry Jones terry at jon.es
Sat Jul 18 14:49:58 CEST 2009


>>>>> "Michael" == Michael Foord <fuzzyman at gmail.com> writes:
Michael> The bit that has to be *added* in Python (and usually isn't added
Michael> because it isn't at all obvious) is:

Michael> Exceptions are not reraised if the finally returns or breaks.

OK.

>> If finally propagated exceptions,
Michael> It does.

Sorry - I meant propagates the try exception even in the case that the
finally does a return, break, or raises itself.

>> It begins to get complicated.

Michael> No, it gets simpler - no special cases for the exception handling
Michael> of finally in the presence of a return.

I think it's more complex. Either, or both, of the try block and the
finally block may return/raise etc. What to do when those things conflict?
Which block's opinion has priority? It seems clear (to me) that the finally
block should have the final word, no matter what - including (perhaps even
especially) if its ultimate conclusion conflicts with what the try block did.

Terry



More information about the Python-ideas mailing list