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

Q: Throwable是否是受查异常?
A: 是html

Java规范中,对非受查异常和受查异常的定义是这样的: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处理。
  • 余下的受查异常,是在编写程序时没法提早预料到的,如文件读写异常、数据库访问异常等,这并非程序自己的错误,为了保证程序的健壮性,这些异常必须被捕获。
相关文章
相关标签/搜索