ITeye博客

unchecked exception及checked exception的区别

Jseeker · 2010-12-14 10:43 · 编程语言 · Markdown

unchecked exception及checked exception的区别

1. checked exception

a. 都是Exception的子类,若子类可能抛出X异常,则父类也必须throws X异常,效率低,耦合度高。

b. 需要强制catch,否则编译器直接报错。

 

2. unchecked exception

a. 都是RuntimeException的子类。

b. 非必须catch,是无法预料的。比如,list..size(),若list=null, 则会抛出NullPointerException,该异常是一个RuntimeException, 也就是unchecked exception。

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。