捕获异常
try:
逻辑代码块
except ExceptionType as err:
异常处理方法
捕获多个异常
try:
逻辑代码块
except (ExceptionType1, ExceptionType2,…) as err:
异常处理方法
捕获所有可能发生的异常
try:
逻辑代码块
except (ExceptionType1, ExceptionType2,…) as err:
异常处理方法
except Exception as err:
异常处理方法
finally处理
try:
逻辑代码块
except (ExceptionType1, ExceptionType2,…) as err:
异常处理方法
except Exception as err:
异常处理方法
finally:
无论是否有异常产生,都会执行这里的代码块!
函数嵌套异常传递
函数嵌套调用时,如果执行过程中放生异常,若内层函数没有捕捉,异常会被逐层抛给外层调用者。






217

被折叠的 条评论
为什么被折叠?



