python之处理异常
# 多分支报错 try: print("hello") # print(x) print("======>") except KeyError as k: raise KeyError() # print(k) except NameError as n: print(n) else: print("try code 没有异常,就执行我") finally: print("无论有无异常都执行,一般执行清理操作") # 万能异常 try: print(x) except Exception as e: print(e) else: print("try code 没有异常,就执行我") finally: print("无论有无异常都执行,一般执行清理操作")