为什么运行时异常是未经检查的异常? [英] Why runtime exception is unchecked exception?

查看:138
本文介绍了为什么运行时异常是未经检查的异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,如果任何类扩展了异常,则它将被检查异常。 运行时异常也扩展了异常。那么它如何 unchecked exception



这个特殊情况是否像编译器中有一个自定义检查?



编辑:我对 检查v / s未检查异常 和他们的利弊& cos等等,我们之间的区别不在于他们之间的答案。

解决方案

在规范中明确指出,第11.1.1节


RuntimeException 及其所有子类统称为运行时异常类



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



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


编译器肯定知道 RuntimeException


Generally if any class extends Exception , it becomes checked exception. Runtime exception also extends Exception. Then how is it unchecked exception?

Is it like they have a custom check in compiler for this special case?

EDIT : I have proper idea about checked v/s unchecked exception and their pros & cos etc. I don't except differences between them in answer.

解决方案

It's explicitly in the specification, section 11.1.1:

RuntimeException and all its subclasses are, collectively, the runtime exception classes.

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.

So yes, the compiler definitely knows about RuntimeException.

这篇关于为什么运行时异常是未经检查的异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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