博客大巴,别克君威gs超级运动版,三毛流浪记第二部
检测和处理异常 上下文管理 触发异常 断言 标准异常
第一种语句:try-except
try: pass except Exception, e: # 捕获所有异常 raise e # 抛出捕获的异常
第二种语句:try-except-except-except
try: pass except Exception1, reason1: raise except Exception2, reason2: raise except Exception3, reason3: raise
第三种语句:处理多个异常的except语句
try: pass except (Exception1,Exception2), reason: raise
第四种语句:try-except-else语句
try: pass except Exception, e: raise e else: # try范围中没有检测到异常时,执行else语句 pass
第五种语句:try-except-finally语句
try: pass except Exception, e: raise e finally: # 无论异常是否发生,是否捕捉到,都会执行该语句 pass
第六种语句:try-except-else-finally
try: pass except Exception, e: raise else: pass finally: pass
第七种语句:try-finally
try: pass finally: pass
with open('/etc/pas','r') as f: for eachline in f:
try: pass except Exception, e: raise
断言语句:如果断言成功不采取任何措施,否则触发断言错误的异常
assert 1 == 0 Traceback (most recent call last): File "E:\code\DA\da.py", line 5, in assert 1 == 0 AssertionError
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Python爬虫:Request Payload和Form Data的简单区别说明
浅谈Python中threading join和setDaemon用法及区别说明
Python3-异步进程回调函数(callback())介绍
python继承threading.Thread实现有返回值的子类实例
Python中使用threading.Event协调线程的运行详解
网友评论