获取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

posted on 2014-08-27 13:49  leafs  阅读(129)  评论(0编辑  收藏  举报

导航