Best way to handle exceptions with try/finally

Thomas Guettler niemand.leermann at thomas-guettler.de
Wed May 24 07:59:47 EDT 2006


Am Tue, 23 May 2006 12:47:05 -0700 schrieb Carl J. Van Arsdall:

> Hey python people,
> 
> I'm interested in using the try/finally clause to ensure graceful 
> cleanup regardless of how a block of code exits.  However, I still am 
> interested in capturing the exception.

You can reraise the exception:

try:
    something()
except:
    cleanup()
    raise # reraise the caught exception

-- 
Thomas Güttler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
Spam Catcher: niemand.leermann at thomas-guettler.de




More information about the Python-list mailing list