方式一:
try
检测范围
except Exception[ as reason]:
出现异常(Exception)后的处理代码
方式二:
方式一:
try: f = open(‘我为什么是一个文件.txt‘) print(f.read()) f.close() except OSError: print(‘文件出错拉T_T‘)
运行结果:
[fengjunjie@localhost ~]$ python3 test.py
文件出错拉T_T
原文:http://www.cnblogs.com/fengjunjie-w/p/7504845.html