Does Python do try: except: finally: ?

Jeremy Fincher tweedgeezer at hotmail.com
Thu Mar 20 05:13:56 CET 2003


"Ulrich Petri" <ulope at gmx.de> wrote in message news:<b5b0de$253ft3$1 at ID-67890.news.dfncis.de>...
> 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?

Blanketly catching exceptions is a bad idea -- you shouldn't catch
certain exceptions (KeyboardInterrupt, SystemExit, etc.)  "finally"
exists so you can do cleanup without catching the exception that was
raised.

Jeremy




More information about the Python-list mailing list