[Python-Dev] Pre-PEP: Unifying try-except and try-finally

Reinhold Birkenfeld reinhold-birkenfeld-nospam at wolke7.net
Wed May 4 21:33:29 CEST 2005


Tim Peters wrote:
> [Guido]
>> I'm +1 on accepting this now -- anybody against?
> 
> I'm curious to know if you (Guido) remember why you removed this
> feature in Python 0.9.6?  From the HISTORY file:
> 
> """
> New features in 0.9.6:
> - stricter try stmt syntax: cannot mix except and finally clauses on 1 try
> """
>
> IIRC (and I may well not), half of people guessed wrong about whether
> an exception raised in an "except:" suite would or would not skip
> execution of the same-level "finally:" suite.

With the arrival of Java and C#, which both have this feature,
I think the wrong guesses are minimized.

I think the behaviour of the "else" clause is much harder to guess,
mainly when used with the looping constructs.

> try:
>     1/0
> except DivisionByZero:
>     2/0
> finally:
>     print "yes or no?"
> 
> The complementary question is whether an exception in the "finally:"
> suite will be handled by the same-level "except:" suites.

No, as except clauses can only occur before the finally clause, and execution
should not go backwards.

> There are obvious answers to both, of course.  The question is whether
> they're the _same_ obvious answers across responders <0.7 wink>.

Reinhold

-- 
Mail address is perfectly valid!



More information about the Python-Dev mailing list