Java中的Throwable類是不是受查異常?

來源:互聯網
上載者:User

標籤:pos   runtime   程式   code   ora   run   owa   markdown   img   

Q: Throable是不是受查異常?
A: 是

在Java規範中,對非受查異常和受查異常的定義是這樣的:

  • The unchecked exception classes are the run-time exception classes and the error classes.
  • The checked exception classes are all exception classes other than the unchecked exception classes. That is, the checked exception classes are Throwable and all its subclasses other than RuntimeException and its subclasses and Error and its subclasses.

也就是說,除了run-time exception和其子類,以及error和其子類,其它的所有異常都是受查異常。

Java中的異常分類如下:

  • Error通常是一些底層的和硬體有關的錯誤,與程式本身無關,不應該被捕獲,因為捕獲了無能為力。
  • RuntimeException是程式本身出錯拋出的異常,這類錯誤一定是程式員本身邏輯錯誤或不嚴謹造成的,可以捕獲也可以不捕獲,如果不主動捕獲則會被JVM處理。
  • 餘下的受查異常,是在編寫程式時無法提前預料到的,如檔案讀寫異常、資料庫訪問異常等,這並不是程式本身的錯誤,為了保證程式的健壯性,這些異常必須被捕獲。

Java中的Throwable類是不是受查異常?

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.