Java中的Throwable类是不是受查异常?

是。

Java规范中,对非受查异常和受查异常的定义是这样的:

  • The unchecked exception classes are the run-time exception classes and the error classes.
  • The checked exception classes are all exception classes other than the unchecked exception classes. That is, the checked exception classes are Throwable and all its subclasses other than RuntimeException and its subclasses and Error and its subclasses.

也就是说,除了run-time exception和其子类,以及error和其子类,其它的所有异常都是受查异常。


Java中的异常分类如下:

  • Error通常是一些底层的和硬件有关的错误,与程序本身无关,不应该被捕获,因为捕获了无能为力。
  • RuntimeException是程序本身出错抛出的异常,这类错误一定是程序员本身逻辑错误或不严谨造成的,可以捕获也可以不捕获,如果不主动捕获则会被JVM处理。
  • 余下的受查异常,是在编写程序时无法提前预料到的,如文件读写异常、数据库访问异常等,这并不是程序本身的错误,为了保证程序的健壮性,这些异常必须被捕获。
Spring Security验证流程剖析及自定义验证方法 Java中的类型擦除与桥方法

评论(需梯子)

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×