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()
它编写了异常行的m1()
调用行的编号,但是我需要在函数m1
中准确地知道异常行的编号。你能告诉我怎么知道吗?你知道吗
要获取异常,必须循环
.tb_next
它将输出
line 25
not29
或不带m1()
的行相关问题 更多 >
编程相关推荐