演示异常

2014-10-26 0 771
演示异常
#coding=utf-8
#异常用法

import sys

#----------------
#sys.exc_info()[2].tb_lineno值不是固定的
try:
    x=1/0
except Exception as e:
    print "Exception:[%s][%s]" % (sys.exc_info()[2].tb_lineno, str(e)) 
finally:
    print "This is finally "

#----------------  
try:
    raise Exception("HAHAHA")
except Exception as e:
    print "Exception:[%s][%s]" % (sys.exc_info()[2].tb_lineno, str(e)) 

#----------------
try:
    1/0
except ZeroDivisionError:
    print 'aaaaaaaaaaaa'
except:
    print 'bbbbbbbbbbb'
    
#----------------
try:
    x=1/0
except Exception as e:
    print "Exception:[%s][%s]" % (sys.exc_info()[2].tb_lineno, str(e)) 

遇见资源网 python 演示异常 http://www.ox520.com/14858.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务