gpt4 book ai didi

java - Java 语言在哪里定义 Throwable 是否被检查?

转载 作者:行者123 更新时间:2023-12-01 18:33:55 26 4
gpt4 key购买 nike

Exception 和 RuntimeException 都继承自 Throwable,并且没有实现任何接口(interface)来判断它们是否被检查。

哪里指定检查Exception,不检查RuntimeException?它是在语言还是 JVM 中硬连线的吗?

最佳答案

它在 Java Language Specification section 11.1.1 中定义.

Throwable and all its subclasses are, collectively, the exception classes.

Exception is the superclass of all the exceptions from which ordinary programs may wish to recover.

Error is the superclass of all the exceptions from which ordinary programs are not ordinarily expected to recover.

Error and all its subclasses are, collectively, the error classes.

[...]

The class RuntimeException is a direct subclass of Exception. RuntimeException is the superclass of all the exceptions which may be thrown for many reasons during expression evaluation, but from which recovery may still be possible.

RuntimeException and all its subclasses are, collectively, the run-time exception classes.

The unchecked exception classes are the run-time 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.

关于java - Java 语言在哪里定义 Throwable 是否被检查?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22893136/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com