the death of lecter

Tim Peters tim_one at email.msn.com
Tue Sep 12 00:15:26 EDT 2000


[Michal Wallace]
>>    * extended 'try' syntax:
>>          try:
>>              print 'do something'
>>          except:
>>              print 'catch errors'
>>          finally:
>>              print 'clean up' # not allowed in real Python

[Alex Martelli]
> You just have to nest it:
>         try:
>             try:
>                 print "foo"
>             except:
>                 print "errors"
>         finally:
>             print "clean up"
>
> I do agree that an optionally finally-clause after 1 or more except
> clauses (and possibly an else clause too) on a try would make for a
> nice alternative to this rather cumbersome nested syntax where except
> (& maybe else) and finally are mutually exclusive.
>
> "Why you'd want to do this" seems rather obvious -- catch errors
> AND also guarantee some finalization.

Python used to allow this.  It was removed in version 0.9.6 (see
Misc/HISTORY).  As I recall, no matter *how* Guido tried to implement it in
versions prior to 0.9.6,  exactly half <wink> of all programmers assumed the
wrong answer to whether uncaught exceptions raised in an "except" clause
would or would not cause the "finally" block to get skipped.  Well, sure, of
*course* the right answer is obvious to us <wink>.  Nesting makes it obvious
to everyone, though, so that's what survived.






More information about the Python-list mailing list