import sys def printTrace(frame, event, arg): if (event == 'exception'): print arg print 'Arg size=', len(arg) print arg[2] return printTrace def foo(): print 'Here foo' sys.settrace(printTrace) foo() import threading try: dir(pippo) except: print "Error caught"