What about try:except:finally

Tim Peters tim_one at email.msn.com
Sun Jul 9 12:14:12 EDT 2000


[Martin von Loewis]
> That also shows that having try:except:finally is perhaps not a good
> idea. Given
>
> try:
>   A
> except:
>   B
> finally:
>   C
>
> is that the same as
>
> try:
>   try:
>     A
>   finally:
>     C
> except:
>   B
>
> or as
>
> try:
>   try:
>     A
>   except:
>     B
> finally:
>   C
>
> or is it something else? If so, what would it be? And why not one of
> the others?

Sorry that I haven't followed this whole thread, but if no old-timer has
pointed it out before, Python *used* to allow try/except/finally all at the
same level.  For exactly the reason Martin gave here, that was removed
before Python's first public release.  From Misc/HISTORY:

    New features in 0.9.6:
    - stricter try stmt syntax: cannot mix except and finally clauses on 1
try

The ambiguity Martin pointed out here was real:  it's not at all obvious
what mixing them means, and about half <wink> the users guessed wrong about
what the implementation actually did.

explicit-is-better-than-implicit-ly y'rs  - tim






More information about the Python-list mailing list