Re-throwing an exception without loosing the stack trace

Chris Liechti cliechti at gmx.net
Tue Feb 12 19:27:13 EST 2002


"Clark C . Evans" <cce at clarkevans.com> wrote in 
news:mailman.1013552683.30067.python-list at python.org:

> How do I catch and then re-throw an exception without
> loosing the information about the stack trace?  I've
> looked around alot and don't see the "obvious" answer.

try a simple, naked "raise" ;-)

> Thanks!
> 
> Clark
> 
> P.S. I need to catch exceptions to clean up some
>      resources (database locked table), but
>      then I want to re-throw the error... in
>      it's original stack trace so that I can
>      find it... loosing the stack trace makes
>      for brutal debugging.

look at the traceback module too.
you can print out an exception with
"traceback.print_exc(file=sys.stderr)" and still continue your prog.
you can also save a copy of the stack trace with
"sys.exc_info()" and evaluate it later.

chris

-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list