Python--异常
1 # -*- coding:utf-8 -*- 2 name = 'tj' 3 try: 4 int(name) 5 except (IndexError,KeyError) as e: # 当有IndexError或KeyError时执行 6 print(e) 7 print(1) 8 except ValueError as e: # 当有ValueError时执行 9 print(e) 10 print(2) 11 except Exception as e: # 抓取所有异常 12 print(e) 13 print(3) 14 else: # 无异常时执行 15 print("一切正常") 16 finally: # 无论如何都执行 17 print("anywhere")