Python获取异常的各种信息
文章目录
在python中,异常信息的获取对于程序的调试非常重要,可以有助于快速定位有错误程序语句的位置。下面介绍几种python中获取异常信息的方法,这里获取异常(Exception)信息采用try…except…程序结构。如下所示:
try:
...
except Exception as error:
...
error.class.name: 类名称
获取异常对象所属的类的名称
try:
function()
except Exception as error:
print 'type is:', error.__class__.__name__
str(error):异常信息
给出异常信息,不包括异常信息的类型,如1/0的异常信息
'integer divis