- 分類:throwable的子類
有 Error 和 Exception
- Error:一般是指與虛擬機相關(guān)的問題嚼吞,如系統(tǒng)崩潰请垛,虛擬機錯誤奏瞬,內(nèi)存空間不足,方法調(diào)用棧溢等指黎。對于這類錯 誤的導(dǎo)致的應(yīng)用程序中斷,僅靠程序本身無法恢復(fù)和和預(yù)防州丹,遇到這樣的錯誤醋安,建議讓程序終止。
/**
* An {@code Error} is a subclass of {@code Throwable}
* that indicates serious problems that a reasonable application
* should not try to catch. Most such errors are abnormal conditions.
* The {@code ThreadDeath} error, though a "normal" condition,
* is also a subclass of {@code Error} because most applications
* should not try to catch it.
* <p>
* A method is not required to declare in its {@code throws}
* clause any subclasses of {@code Error} that might be thrown
* during the execution of the method but not caught, since these
* errors are abnormal conditions that should never occur.
*
* That is, {@code Error} and its subclasses are regarded as unchecked
* exceptions for the purposes of compile-time checking of exceptions.
- Exception:表示程序可以處理的異常墓毒,可以捕獲且可能恢復(fù)吓揪。遇到這類異常,應(yīng)該盡可能處理異常所计,使程序恢復(fù)運行柠辞,而不應(yīng)該隨意終止異常。
**
* The class {@code Exception} and its subclasses are a form of
* {@code Throwable} that indicates conditions that a reasonable
* application might want to catch.
*
* <p>The class {@code Exception} and any subclasses that are not also
* subclasses of {@link RuntimeException} are <em>checked
* exceptions</em>. Checked exceptions need to be declared in a
* method or constructor's {@code throws} clause if they can be thrown
* by the execution of the method or constructor and propagate outside
* the method or constructor boundary.
- 其中Exception可分為2種:
RuntimeException:運行期異常主胧,系統(tǒng)異常
可以處理也可以不處理叭首,編譯器不強制用 try..catch 處理或用 throws 聲明,所以系統(tǒng)異常也稱為 unchecked 異常踪栋。
eg:NullPointerException,IndexOutOfBoundsException,ClassCastException,ClassNotFoundException 焙格, IllegalArgumentException,UnsupportedOperationException夷都。CheckedException: 也成編譯器異常
編譯器強制普通異常必須 try..catch 處理或用 throws 聲明繼 續(xù)拋給上層調(diào)用方法處理
eg:CloneNotSupportedException