python 異常處理

來源:互聯網
上載者:User

標籤:沒有   情況下   執行   code   錯誤類型   擷取   index   異常處理   pre   

#能夠預料到的異常可以這樣做try :    print()    #執行這段代碼有沒有出錯,如果有出錯# except SyntaxError as e: ###SyntaxError錯誤類型的代碼#     print()# ###as e 代表擷取到誤後的結果# ##如果try:這裡執行多個結果有的錯誤,還可以 多加:# except IndexError as e:#     print("")###也可以這樣:except (SyntaxError,IndexError) as e:    print()    ##這樣寫的話,你就不會知道那一句代碼出錯了except Exception as e:    print("未知錯誤,也就是全部錯誤都可以檢測到")else:    print("全部沒有錯誤的情況下會執行這個")finally:    print("不管有沒有錯誤都會執行")

 

python 異常處理

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.