return from finally clause

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


"D-Man" <dsh8290 at rit.edu> wrote in message
news:mailman.992098154.29963.python-list at python.org...
> On Fri, Jun 08, 2001 at 09:16:43PM -0400, Steve Holden wrote:
> | "Joshua Marshall" <jmarshal at mathworks.com> wrote in message
> | news:9frdgk$pnd$1 at news.mathworks.com...
> | > "J?rgen Hermann" <jh at web.de> wrote:
> | >
> | > > That means that if you (accidently?) return within a finally clause,
you
> | > > 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
all
> | it's a programming error. What action would be best? Raise another
exception
> | 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".

regards
 Steve

regards
 Steve






More information about the Python-list mailing list