Python----物件導向---異常處理

來源:互聯網
上載者:User

標籤:ace   eof   error   邏輯   運行   most   ali   recent   int   

一、什麼是異常

異常是錯誤發生的訊號,一旦程式出錯,並且程式沒有處理這個錯誤,那麼就會拋出異常,並且程式的運行隨之終止

例如:

 1 print(‘1‘) 2 print(‘2‘) 3 print(‘3‘) 4 int(‘aaaa‘) 5 print(‘4‘) 6 print(‘5‘) 7 print(‘6‘) 8  9 結果為:10 11 Traceback (most recent call last):12 113 214   File "C:/Users/xu516/PycharmProjects/Python全棧開發/第三模組/物件導向編程/32 異常處理.py", line 6, in <module>15 316     int(‘aaaa‘)17 ValueError: invalid literal for int() with base 10: ‘aaaa‘

報錯後後面的代碼沒有被執行

二、錯誤分為兩種

1、語法錯誤

例如:

 1 print(xxx 2  3 if 1 > 3 4  5 結果為: 6  7   File "C:/Users/xu516/PycharmProjects/Python全棧開發/第三模組/物件導向編程/32 異常處理.py", line 15 8      9     ^10 SyntaxError: unexpected EOF while parsing

2、邏輯錯誤

 

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.