gpt4 book ai didi

java - 是什么使得子类(即 RuntimeException 未被检查并且异常被检查)成为可能?

转载 作者:行者123 更新时间:2023-11-30 10:08:08 26 4
gpt4 key购买 nike

是什么让编译器认为 RuntimeException 未被检查,尽管 RuntimeException 也是 Exception 类型。但是Exception是checked exception吗?

最佳答案

That is, the checked exception classes are Throwable and all its subclasses other than RuntimeException and its subclasses and Error and its subclasses.

JLS 11 > Exceptions > The Kinds of Exceptions

这是规则,编译器知道它。给定异常是 RuntimeException 的子类这一事实(比方说 givenException instanceof RuntimeException)足以让编译器不将其视为检查异常。

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.

JLS 11 > Exceptions > The Kinds of Exceptions

关于java - 是什么使得子类(即 RuntimeException 未被检查并且异常被检查)成为可能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53900392/

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