gpt4 book ai didi

java - Java 如何知道 RuntimeExceptions 未被检查?

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:57:43 26 4
gpt4 key购买 nike

Java 编译器如何知道 java.lang.RuntimeException 及其子类是未检查的,因为它们继承自 java.lang.Exception,这是一个已检查的异常?我查看了代码,类中似乎没有任何内容告诉编译器。

最佳答案

因为它在 specification of the language # 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.

所以它不是各种异常类代码的一部分,它只是语言定义的约定,编译器必须实现才能符合。

关于java - Java 如何知道 RuntimeExceptions 未被检查?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14879268/

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