如何打印异常? [英] How to print an exception?
本文介绍了如何打印异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何打印python异常?
How to print python exception?
示例:
try:
action()
except:
print "Unexpected error:", sys.exc_info()[0]
打印:
意外错误:< type'exceptions.TypeError'>
它对我来说没有太多信息.
It does not have much information for me.
推荐答案
使用跟踪模块:
try:
action()
except:
import traceback
traceback.print_exc()
这篇关于如何打印异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文