码迷,mamicode.com
首页 > 编程语言 > 详细

Python 异常处理

时间:2018-03-15 20:17:08      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:imp   try   程序   txt   xxx   col   div   style   finally   

 基础的处理

一个简单的小例子

 



1 import time 2 try: 3 time.sleep(2) # 程序延时2秒 4 open("xxx.txt") 5 print("111111111111111") 6 7 8 except (NameError, FileNotFoundError): 9 print(*-*-*) 10 except Exception as ret: 11 print("如果有异常,并不在except中,执行(捕获所有异常)") 12 print(ret)#打印异常类型 13 else: 14 print("没有异常执行") 15 finally: 16 print("产没产生异常都执行") 17 18 print("结束")

 结果

1 *-*-*
2 产没产生异常都执行
3 结束

 

Python 异常处理

标签:imp   try   程序   txt   xxx   col   div   style   finally   

原文地址:https://www.cnblogs.com/Burtit/p/8575922.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!