return from finally clause

Steve Holden sholden at
Mon Jun 11 06:53:41 EDT 2001

"D-Man" <dsh8290 at> wrote in message
news:mailman.992098154.29963.python-list at
> On Fri, Jun 08, 2001 at 09:16:43PM -0400, Steve Holden wrote:
> | "Joshua Marshall" <jmarshal at> wrote in message
> | news:9frdgk$pnd$1 at
> | > "J?rgen Hermann" <jh at> wrote:
> | >
> | > > That means that if you (accidently?) return within a finally clause,
> | > > effectively eat the exception. This should be documented, or fixed.
> | >
> | > That's unpleasant.  I hope it's a bug.
> | >
> | Well, I think we  can agree that there's a certain inconsistency in
> | returning from a function with an exception active like that. So most of
> | it's a programming error. What action would be best? Raise another
> | when the "return" is executed?
> There is no exception acvite -- you have handled it and now want to
> return a value instead of propagating the exception.
Just to pick a nit, the finally clause is being executed in the context of a
current exception, and if it hadn't altered the flow of control by executing
a return the interpreter's action would have been to automatically re-raise
the same exception at the end of the finally suite.

This differs from the case where the finally clause is executed after the
try suite when no exception has been raised. Hence my mention of an
exception "being active".



More information about the Python-list mailing list