Java如何知道RuntimeExceptions是否被取消选中? [英] How does Java know that RuntimeExceptions are unchecked?

查看:110
本文介绍了Java如何知道RuntimeExceptions是否被取消选中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How does the Java compiler know that java.lang.RuntimeException and its subclasses are unchecked, since they inherit from java.lang.Exception, which is a checked exception? I looked into the code and doesn't seem to be anything inside the class that tells it to the compiler.

推荐答案

因为它被定义为语言#11.1.1的规范



  • 未经检查的异常类是运行时异常类和错误类。

  • 检查的异常类除了未检查的异常类之外都是异常类。也就是说,检查的异常类除了RuntimeException及其子类和Error及其子类之外,都是Throwable的子类。

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

So it is not part of the code of the various exception classes, it is only a convention defined by the language, that compilers must implement to be compliant.

这篇关于Java如何知道RuntimeExceptions是否被取消选中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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