用户登录
用户注册

分享至

演示异常

  • 作者: 绯梦二十三_
  • 来源: 51数据库
  • 2022-08-12
#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)) 
软件
前端设计
程序设计
Java相关