Python catch any exception, and print or log traceback with variable values
By looking at the source of cgitb.py
, you should be able to use something like this:
import sys
import traceback
import cgitb
def handleException(excType, excValue, trace):
print 'error'
cgitb.Hook(format="text")(excType, excValue, trace)
sys.excepthook = handleException
h = 1
k = 0
print h/k