2018-12-13
阅读量:
738
用try语句处理异常
try语句可以有多个except子句,以指定不同异常的处理程序。请注意,最多只会执行一个处理程序。
# Program to handle multiple errors with one except statement
try :
a = 3
if a < 4 :
# throws ZeroDivisionError for a = 3
b = a/(a-3)
# throws NameError if a >= 4
print "Value of b = ", b
# note that braces () are necessary here for multiple exceptions
except(ZeroDivisionError, NameError):
print "\nError Occurred and Handled"






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论