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")

 

posted @ 2020-08-04 21:13  NorthFeng  阅读(144)  评论(0编辑  收藏  举报