异常,错误都是同一种父类:java.lang.Throwable
IllegalStateException属于RuntimeException,RuntimeException又是Exception的子类
RuntimeException的特点是非受检异常,区别于受检异常,也就是java系统允许可以不catch(当然也可以人为catch,比如特殊业务逻辑需要),在运行时碰到就抛出
关键RuntimeException为什么会被系统允许不被catch...
也就是可能会抛出RuntimeException的方法不被要求在方法throws clause中声明。
原因我想RuntimeException相对那些受检异常有更多的不确定性和普遍性,如果改为受检异常,代价较大,也没必要,因为一般它总不为业务逻辑所容(受检异常就容?也不容!是不是RuntimeException更不为所容?因此不catch直接抛出导致中断程序?也可能中不中断都不是重点,实现代价才是重点)。
对比几个可能会有更好的实感:
受检异常:ClassNotFoundException, SQLException, NoSuchMethodException...
RuntimeException:NullPointerException, IllegalArgumentException, ArithmeticException
http://bbs.csdn.net/topics/390279427?page=1#post-392900808
RuntimeExceptions are thrown for things that were preventable.
Exceptions are thrown for things that were unpreventable but recoverable
Errors are thrown for things that were unpreventable and unrecoverable.
For example, NullPointerExceptions can always be avoided and are therefore unchecked exceptions. A RemoteException could occur when there is a network failure, which cannot be reasonably prevented before the method call and therefore is checked.