try-except语句:定义了进行异常监控的一段代码,并且提供了处理异常的机制
try:
try_suite
except Exception[,reason]:
except_suite
try语句可以带多个 except子句,还可以有一个可选的else子句
try:
try_suite
except Exception[,reason]:
suite_exception1
except (Exception2,Exception3,...)[,reason]:#一次捕获多个异常时要定义为元组
suite_
except:#空except语句用于捕获一切异常
suite_
else:
else_suite
except分句个数没有限制,但else只能有一个
没有异常发生时,else分句才会执行
没有符合的except分句时,异常会向上传递到程序中的之前进入的try中或者到进程的顶层