异常处理—checked exception 和 unchecked exception
Posted jayinnn
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了异常处理—checked exception 和 unchecked exception相关的知识,希望对你有一定的参考价值。
异常的Root Class是Throwable,Throwable派生了Error和Exception。
Java 8 API Doc中对checked exception和unchecked exception 的说明:
1. checked exception:(在Exception类中的说明)
The class Exception and any subclasses that are not also subclasses of RuntimeException are checked exceptions.
2. unchecked exception:
(在Error类中说明)
Error and its subclasses are regarded as unchecked exceptions for the purposes of compile-time checking of exceptions
(在RuntimeException类中的说明)
RuntimeException and its subclasses are unchecked exceptions.
3. checked exception:编译器要求对其进行显示的捕获或抛出,例如,IOException,SQLException;
unchecked exception:一般发生在运行期,编译器不要求对其进行显示的捕获或抛出,例如NullPointerException,ClassCastException;
RuntimeException
and its subclasses are unchecked exceptions.
以上是关于异常处理—checked exception 和 unchecked exception的主要内容,如果未能解决你的问题,请参考以下文章
Java中Error和Exception的异同以及运行时异常(Runtime exception)与检查型异常(checked exception)的区别
Java 中的两种异常(Checked exceptions 和 Unchecked exceptions)