python 异常处理
name = ["test","测试"]data = {}try: # open("oooo.txt") # name[3] # data["name"] a = 1 print(a)except (KeyError,IndexError) as e: print("没有这个key", e)except KeyError as e: print("没有这个key",e)except IndexError as e: print("列表操作错误",e)except Exception as e:#抓取所有错误 print("未知错误",e)else : print(‘一切正常‘)finally: print(‘不管有没有错,都执行‘)#自定义异常class WupeiqiException(Exception): def __init__(self, msg): self.message = msg def __str__(self): return self.messagetry: raise WupeiqiException(‘我的异常‘)except WupeiqiException as e: print(e)
相关推荐
kevinweijc 2020-08-18
kikaylee 2020-08-18
寻常白昼 2020-08-15
shunelly 2020-08-09
liangzhouqu 2020-07-28
JessePinkmen 2020-07-26
Lexan 2020-06-22
heimicms 2020-06-14
tianyafengxin 2020-06-08
lynjay 2020-06-06
cenylon 2020-06-04
lqxqust 2020-06-03
宿舍 2020-05-29
Wonder的学习 2020-05-11
明天你好 2020-05-09
阿艾辣悟叩德 2020-05-06
致终将努力的我们 2020-05-05
JakobHu 2020-04-26