java异常的定义,被检查的Java异常的定义?

I see that one definition can be this:

Generally RuntimeExceptions are exceptions that can be prevented

programmatically.

But that is still not the definition of a checked exception. I thought checked exceptions were "exceptions that can be handled at compile-time". Is that correct and/or can you tell me more?

I also read this on the site, can you explain the quote?

Many people say that checked exceptions (i.e. these that you should

explicitly catch or rethrow) should not be used at all.

Can I just learn what the definition is? I also read somewhat unexpectedly:

NumberFormatException is unchecked`

But I would think that NumberFormatException is checked since I would handle that at compile-time. Can you please help me understand? I've done some Java programming but I never wrote my own exception class, why would I need that?

p9xqv.jpg

Update

A definition is given is the SCJP book by Sierra / Bates:

FkKXs.png

解决方案

A checked exception is defined as any subclass of java.lang.Throwable (including Throwable itself) which is not a subclass of java.lang.Error or java.lang.RuntimeException. The guidelines you saw are just that, guidelines, designed to help you understand the intent of runtime exceptions.

See the Java Language Specification, section 11.1.1

The unchecked exception classes are the runtime 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 all subclasses of

Throwable other than RuntimeException and its subclasses and Error and its

subclasses.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值