java 的Exception和Error

Exception和Error都是Throwable的子类,下面是javase文档关于error的介绍

An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions. The ThreadDeath error, though a "normal" condition, is also a subclass of Error because most applications should not try to catch it.

A method is not required to declare in its throws clause any subclasses of Error that might be thrown during the execution of the method but not caught, since these errors are abnormal conditions that should never occur. That is, Error and its subclasses are regarded as unchecked exceptions for the purposes of compile-time checking of exceptions.

error是一般应用都不该去捕获的,这是严重的错误。

Exception是异常,是正常的系统也有可能出现的意料之外的情况。

Exception分为检查异常和非检查异常,检查异常要求在编写程序的时候进行捕获,非检查型异常并不需要。非检查型异常只有RuntimeException和它的子类。其他都是检查型异常。RuntimeException异常可以编程人员可以避免的,比如NullPointException和ArrayIndexOutOfBoundException,ClassCastException,对于空指针,程序员可以使用之前进行判断而避免异常;对于数组越界,可以进行判断数组是否越界而避免异常;检查型异常主要有IOException,ReflectiveOperationException及他们的子类,比如常见的FileNotFoundException。这类异常是编程人员无法通过改善程序避免的,系统希望应用捕获并且从异常中恢复的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值