码迷,mamicode.com
首页 > 其他好文 > 详细

异常处理—checked exception 和 unchecked exception

时间:2019-06-06 20:58:11      阅读:39      评论:0      收藏:0      [点我收藏+]

标签:exce   mil   nbsp   sse   not   owa   运行   and   要求   

异常的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

标签:exce   mil   nbsp   sse   not   owa   运行   and   要求   

原文地址:https://www.cnblogs.com/jayinnn/p/10986633.html

(0)
(0)
   
举报
评论 一句话评论(0
0条  
登录后才能评论!
© 2014 mamicode.com 版权所有 京ICP备13008772号-2
迷上了代码!