you can also make use of exception handlers to replace python' default top-level exception-handling behavior by wrapping an entire program (or call to itin an outer try in your top-level codeyou can catch any exception that may occur while your program runsthereby subverting the default program termination in the followingthe empty except clause catches any uncaught exception raised while the program runs to get hold of the actual exception that occurred in this modefetch the sys exc_info function call result from the built-in sys moduleit returns tuple whose first two items contain the current exception' class and the instance object raised (more on sys exc_info in moment)tryrun program exceptall uncaught exceptions come here import sys print('uncaught!'sys exc_info()[ ]sys exc_info()[ ]this structure is commonly used during developmentto keep programs active even after errors occur--within loopit allows you to run additional tests without having to restart it' also used when testing other program codeas described in the next section on related notefor more about handling program shutdowns without recovery from themsee also python' atexit standard library module it' also possible to customize what the top-level exception handler does with sys excepthook these and other related tools are described in python' library manual running in-process tests some of the coding patterns we've just looked at can be combined in test-driver application that tests other code within the same process the following partial code sketches the general modelimport sys log open('testlog'' 'from testapi import moretestsrunnexttesttestname def testdriver()while moretests()tryrunnexttest(exceptprint('failed'testname()sys exc_info()[: ]file=logelseprint('passed'testname()file=logtestdriver(exception idioms