RuntimeException和非RuntimeException
在java的異常類體系中,Error和RuntimeException是非檢查型異常,其他的都是檢查型異常。
所有方法都可以在不聲明throws的情況下拋出RuntimeException及其子類
不可以在不聲明的情況下拋出非RuntimeException
簡單的說,非RuntimeException要自己寫catch塊處理掉。
常見的RuntimeException:
ClassCastException
NullPointerException
ArrayIndexOutOfBoundsException
IllegalArgumentException
NumberFormatException