Python program termination and exception catching

Jason Swails jason.swails at
Sun Apr 10 21:25:41 CEST 2011

Hello everyone,

This may sound like a bit of a strange desire, but I want to change the way
in which a python program quits if an exception is not caught.  The program
has many different classes of exceptions (for clarity purposes), and they're
raised whenever something goes wrong.  Most I want to be fatal, but others
I'd want to catch and deal with.

Is there any way to control Python's default exit strategy when it hits an
uncaught exception (for instance, call another function that exits

An obvious way is to just catch every exception and manually call that
function, but then I fill up my script with trys and excepts which hurts
readability (and makes the code uglier) and quashes tracebacks; neither of
which I want to do.

Any thoughts?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list