被检查的Java异常的定义? [英] Definition of checked Java exception?

查看:108
本文介绍了被检查的Java异常的定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到一个定义可以是这样:

I see that one definition can be this:

通常,RuntimeExceptions是可以避免的异常 以编程方式.

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.

Java:已检查与未检查的异常说明

我能知道定义是什么吗?我也有些意外地阅读:

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

NumberFormatException未选中`

NumberFormatException is unchecked`

但是我认为NumberFormatException已被检查,因为我将在编译时进行处理.你能帮我理解吗?我已经做了一些Java编程,但是我从来没有写过自己的异常类,为什么我需要它?

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?

Sierra/Bates给出了SCJP书的定义:

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

推荐答案

已检查的异常定义为java.lang.Throwable的任何子类(包括Throwable本身),而不是java.lang.Errorjava.lang.RuntimeException的子类.您所看到的准则仅仅是旨在帮助您了解运行时异常的意图的准则.

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.

请参见Java语言规范,第11.1.1节

See the Java Language Specification, section 11.1.1

未经检查的异常类是运行时异常类和错误 课.

The unchecked exception classes are the runtime exception classes and the error classes.

已检查的异常类是除未检查的以外的所有异常类 异常类.也就是说,检查的异常类是的所有子类. 除了RuntimeException及其子类以及Error及其子元素之外的Throwable 子类.

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.

这篇关于被检查的Java异常的定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆