如何在编译时检查已检查的异常? [英] How checked exceptions can be checked at compile time?

查看:85
本文介绍了如何在编译时检查已检查的异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

异常发生在运行时。编译时编译器检查了检查异常。但是如何检查尚未发生的事情。



我尝试了什么:



搜索引用&在线门户...

Exceptions occur at run time.Checked exceptions r checked by compiler at compile time.But how it is possible to check something which hasn't occurred yet.

What I have tried:

searched references & online portals...

推荐答案

引用:

但是怎么可能检查尚未发生的事情。

But how it is possible to check something which hasn't occurred yet.



你说的话没有多大意义。如果您正在询问如何检查在编译时运行时发生的异常,答案是您不能。


What you're saying doesn't make much sense. If you're asking how to check for exception that occur at run-time at compile-time, the answer is you can't.


您显然没有非常努力地搜索 - Google有数百个结果。例如:

指定方法引发的异常(Java™)教程>基本类>例外) [ ^ ]



每个方法都处理由它调用的方法声明的已检查异常,或者声明它可以抛出它们。编译器不需要知道运行时可能发生的情况; 开发人员的确如此。
You obviously didn't search very hard - Google has hundreds of results. For example:
Specifying the Exceptions Thrown by a Method (The Java™ Tutorials > Essential Classes > Exceptions)[^]

Every method either handles the checked exceptions declared by the method(s) it calls, or declares that it can throw them. The compiler doesn't need to know what might happen at runtime; the developer does.


这篇关于如何在编译时检查已检查的异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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