赞
踩
‘’’
异常的嵌套
‘’’
try:
f = open(‘a.txt’)
try:
ret = f.readline()
print(ret)
finally:
f.close()
print(‘文件已关闭’)
except FileNotFoundError:
print(‘文件未找到’)
except UnicodeDecodeError:
print(‘编码错误’)
‘’‘如果try是嵌套的情况,内层的try没有捕获到异常,会传递给外层的try去捕获,如果再没有捕获,再向外层传递’’’
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。