try: finally: question

Mark 'Kamikaze' Hughes kamikaze at
Thu Jul 15 19:50:53 CEST 2004

Peter Hansen <peter at>
wrote on Wed, 07 Jul 2004 12:11:22 -0400:
> I understand that you are arguing that it would be nicer to
> allow try/finally/except.  I agree!  Unfortunately, (a) it was
> removed and is probably unlikely to be added back in, (b) it
> was ambiguous, and the ambiguity has not been resolved, so
> until you or someone else can come up with a better approach
> (and write a PEP) it will stay the way it is.  And that's just
> another fact, so it's pointless to try to argue against it.

  In Java, try...catch...finally has a very clearly defined order: the
try block is performed, if there's an exception it goes to the first
matching catch, and then whether or not there was an exception, the
finally block is performed.  Sometimes this leads to flags that have to
be tested in the finally block to decide what to do, but at least it's
consistent and avoids repeated cleanup code.

  But Python is not Java, nor should it be, and there's no particular
problem with one additional nesting layer to indicate exactly what
sequence things are done in.

 <a href=""> Mark Hughes </a>
"The void breathed hard on my heart, turning its illusions to ice, shattering
 them.  Was reborn, then, free to scrawl own design on this morally blank
 world.  Was Rorschach." --Alan Moore, _Watchmen #6_, "The Abyss Gazes Also"

More information about the Python-list mailing list