Throwable
类是所有异常的根类,RuntimeException
, Error
以及它们所有的子类都叫非检查异常,剩下的都是检查异常。
对于检查异常,例如ClassNotFoundException
,IOException
等,编译器会强制要求用try-catch
进行处理,或在方法头中进行声明。
而对于非检查异常如:RuntimeException
及其子类NullPointerException
, IndexOutOfBoundsException
,IllegalArgumentException
, ArithmeticException
,VirtualMachineError
等,由于这类异常通常反映了不可恢复的编程逻辑错误,为了防止try-catch
的过度滥用,编译器对捕捉或者声明非检查异常没有强制要求。
[1]Introduction to Java Programming 10th. Chapter 12.3