异常处理
1. exception异常
- 多个exception:
try:
····代码块
except 异常1:
except 异常2:
except 异常3:
- exception多个一场用法
try:
····代码块
except (异常1,异常2......) as e:
····print(e.args)
args 是 List item
存储了错误信息的元组
·····print("遇到异常")
3. try-except-else-finally:
try:
····代码块
except 异常 as 变量:
else:
····print("没有异常,执行代码")
finally:
····最终一定要执行的代码
4. 异常处理的传递机制:
5. 抛出自定义异常: raise
关键字