您好,登錄后才能下訂單哦!
1.文件的異常處理:try except FileNotFoundError
try:
open("abc.txt",'r')
except FileNotFoundError:
print("異常了!")
2.name的異常 try except NameError
try :
print(aa)
except NameError:
print("異常了!")
3.可以使用BaseException類處理所以的異常
try:
open("abc.txt",'r')
print(aa)
except BaseException:
print("異常了!")
4.打印異常日志
try:
# open("abc.txt",'r')
print(aa)
except BaseException as msg:
print("異常了!")
print(msg)
5.python中常見的異常:
(1)try ...else..
try:
aa="異常測試"
print(aa)
except Exception as msg:
print(msg)
else:
print("沒有異常!")
(2)try ...finally..
try:
# open("abc.txt",'r')
print(aa)
except BaseException as msg:
print("異常了!")
print(msg)
finally:
print("我都會執行!")
6.拋出異常
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。