以前常用的写法
try: print(a) except Exception, e: print("err exception is %s" % e)
输出
err exception is name 'a' is not defined
异常打印信息不明显
推荐 traceback 来追踪异常
import traceback try: print(a) except Exception, e: print("err exception is %s" % traceback.format_exc())
输出
err exception is Traceback (most recent call last):
File "test.py", line 828, in <module>
print(a)
NameError: name 'a' is not defined