Yes, by registering the sys.excepthook() function:
import sys def myexcepthook(type, value, tb): dump(type, value, tb) sys.excepthook = myexcepthook
This replaces the default hook, which outputs the trace to stderr . It is called whenever an uncaught exception occurs and the interpreter is about to exit.
If you want to reuse the original exception hook from your custom hook, call sys.__excepthook__ :
def myexcepthook(type, value, tb): dump(type, value, tb) sys.__excepthook__(type, value, tb)
Martijn pieters
source share