* Runtime exceptions:
在定義方法時(shí)不需要聲明會(huì)拋出runtime exception; 在調(diào)用這個(gè)方法時(shí)不需要捕獲這個(gè)runtime exception;
runtime exception是從java.lang.RuntimeException或java.lang.Error類衍生出來的。
* Checked exceptions:
定義方法時(shí)必須聲明所有可能會(huì)拋出的checked exception; 在調(diào)用這個(gè)方法時(shí),必須捕獲它的checked exception,
不然就得把它的exception傳遞下去; checked exception是從java.lang.Exception類衍生出來的。
從邏輯的角度來說,checked exceptions和runtime exception是有不同的使用目的的。
checked exception用來指示一種調(diào)用方能夠直接處理的異常情況。而runtime exception則用來指示一種調(diào)用方本身無法處理或恢復(fù)的程序錯(cuò)誤。
java.lang.RuntimeException (程序默認(rèn)拋出的異常,不需要捕獲)
BufferOverflowException,ClassCastException,
DOMException,IndexOutOfBoundsException,
NullPointerException
javax.management.modelmbean.XMLParseException
java.sql.SQLException
...