From this question, I'm now doing error handling one level down. That is, I call a function which calls another larger function, and I want where it failed in that larger function, not in the smaller function. Specific example. Code is:
import sys, os
def workerFunc():
return 4/0
def runTest():
try:
print workerFunc()
except:
ty,val,tb = sys.exc_info()
print "Error: %s,%s,%s" % (
ty.__name__,
os.path.split(tb.tb_frame.f_code.co_filename)[1],
tb.tb_lineno)
runTest()
Output is:
Error: ZeroDivisionError,tmp2.py,8
but line 8 is "print workerFunc()" - I know that line failed, but I want the line before:
Error: ZeroDivisionError,tmp2.py,4