正常的
try..except
无法获取错误行数等信息
可以使用traceback
代码(我写了一个统一装饰器):
import traceback
def func_catch_error(func):
def in_exec(*args,**kargs):
try:
return func(*args,**kargs)
except Exception as e:
#exc_type, exc_obj, exc_tb = sys.exc_info()
print """[Time:{} ,Error Func:{}]
[Error Message Start]
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
{}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[Error Message End]""".format(
time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())),
func.__name__,
traceback.format_exc()
)
return False
return in_exec
网友评论