python 抓取异常

aa={"a":2,"b":1}
for i in range(10):
    aa["a"]=aa["a"]-i
    print(aa["a"])
try:
    ab=aa["c"]-1
except KeyError:        #记录特定异常
    print("没有相应的关键")
try:
    print(ab)
except BaseException as e:   #抓取并记录所有异常
    print("变量不存在")
    print(e)

 

posted @ 2020-10-26 07:18  myrj  阅读(77)  评论(0编辑  收藏  举报