其他分享
首页 > 其他分享> > 异常处理 day07-09

异常处理 day07-09

作者:互联网

l = [1,2,3]
d = {"name":"11"}
import traceback
try:
name = d["name"]
# l[4]
# except KeyError as e:
# print(e)
# print("出现异常了")
# except IndexError as e:
# print("出现下标不存在的异常了")
except Exception as e:
traceback.print_exc() # 打印报错哪一行的
msg = traceback.format_exc() # # 打印报错哪一行的 可写入文件里面
print(msg)
else:
print("没有出现异常")
finally:
print("不管你出不出异常他都会走")

标签:name,09,day07,except,msg,报错,print,异常,exc
来源: https://www.cnblogs.com/huyuemei/p/14881265.html