首页 > 代码库 > 获取python的异常信息1

获取python的异常信息1

代码为:

if __name__ == ‘__main__‘:
   
    try:
        cc = 10/0
    except:
        import sys,traceback
        print ‘begin‘
        print ‘‘.join(traceback.format_exception(*sys.exc_info()))
        print ‘end‘
 

 

=====获取的输出如下:    

begin
Traceback (most recent call last):
  File "G:\codetestcase\python_code\python_case_5\src\log\help.py", line 32, in <module>
    cc = 10/0
ZeroDivisionError: integer division or modulo by zero

end

获取python的异常信息1