Why no try-except-finally ?

MetalOne jcb at iteris.com
Wed Nov 5 18:50:33 CET 2003


I look at it this way.  You are either handling exceptions or you are
letting them propagate up the stack.  If you handle them, then there
is no need for the finally as you will remain in the function and you
can release resources at the bottom of the try/except block.

try: pass
except: pass
#release resources here

If you are letting all exceptions propagate up the stack then there is
no except clause
try: pass
finally: #release resources

Of course there may be cases where some exceptions are handled and
others are not.  Or an exception is partially handled, and then
rethrown.  In these cases, it seems a try/catch/finally idiom would be
useful.

I believe that Delphi works the same way as Python in this regard.




More information about the Python-list mailing list