import sys
import linecache
# copied from somewhere
def PrintException():
exc_type, exc_obj, tb = sys.exc_info()
f = tb.tb_frame
lineno = tb.tb_lineno
filename = f.f_code.co_filename
linecache.checkcache(filename)
line = linecache.getline(filename, lineno, f.f_globals)
print 'EXCEPTION IN ({}, LINE {} "{}"): {}'.format(filename, lineno, line.strip(), exc_obj)
def m1():
# some code
try:
try:
m1()
except:
PrintException()
except:
PrintException()
It writes the Exception line's number of m1()-called line, but I need to know the Exception line's number exactly in function m1. Could you please say how to know it?
try-except?m1()is called and you want the no of line where exactly the exception is (in this case in m1() method definition?).try,tryagain.