Does Python do try: except: finally: ?

Peter Hansen peter at
Thu Mar 20 12:34:59 CET 2003

Ulrich Petri wrote:
> I allways asked myself of what practical use finally (except the syntactical
> "clearness of code") is?
> I can simply write like:
> try:
>     do_this()
> except:
>     print "error"
> #now here is what will be executed next, so what for i do need finally?

Nobody seems to have answered this yet.  You are wrong about 
what will happen... if the print fails.  Okay, maybe your
example cannot fail, but in case it did, your so-called
"finally" code will never get executed!


More information about the Python-list mailing list