首页 > 编程语言 > 详细

Python异常处理

时间:2016-06-09 15:59:47      阅读:322      评论:0      收藏:0      [点我收藏+]

1.try…except…else

try:
    fn = open("aa.txt","r")
    fn.write("这是一个测试文件")
except Exception as e:
    print "错误提示",e.message
else:
    print "写入内容成功"
    fn.close()

2.try…finally

try:
    fn = open("aa.txt","r")
    fn.write("这是一个测试文件")
except Exception as e:
    print "错误提示",e.message
finally:
    print "我都会执行"
    fn.close()

Python异常处理

原文:http://www.cnblogs.com/2star/p/5572393.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!