本文介绍了如何使Eclipse中有误申报异常时,不抓?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让Eclipse来报告错误申报异常时,不抓?结果
例如,如果我声明的方法

 公众诠释的someMethod(INT A,INT B)抛出:IllegalArgumentException  -  {
    ...
}

,然后用它的另一种方法,如

 公众诠释anotherMethod(){
    ...
    返回的someMethod(A,B);
}

我想编译器以anotherMethod报告错误,直到我将捕获或抛出:IllegalArgumentException声明其他方法

 公众诠释anotherMethod()抛出:IllegalArgumentException  -  {}


解决方案

由于您在anotherMethod一个未捕获IOException异常()的Eclipse实际上应报告错误:

 未处理的异常类型为IOException

只有一个未经检查的异常(例如一个RuntimeException)会导致你所描述的行为,而是一个IOException异常是经过检查的异常。

也许你已经在Eclipse中关闭错误报告,但我怀疑如此。您可以在preferences /常规/编辑/文本编辑器/注释/错误检查。确保所有复选框被选中。

注:我的答案是指原来的问题问编辑之前,里面提到一个IOException,而不是一个IllegalArgumentException

How to make Eclipse to report error when declared exception is not caught?
For example, if I declare method as

public int someMethod(int a, int b) throws IllegalArgumentException {
    ...
}

And then use it in another method like

public int anotherMethod() {
    ...
    return someMethod(a, b);
}

I want compiler to report error in anotherMethod, until I will catch IllegalArgumentException or declare another method as

public int anotherMethod() throws IllegalArgumentException {}
解决方案

Eclipse should actually report an error because you have an uncaught IOException in anotherMethod():

Unhandled exception type IOException

Only an unchecked exception (e.g. a RuntimeException) would cause the behaviour you are describing, but an IOException is a checked exception.

Maybe you have turned off error reporting in eclipse, but I doubt so. You can check this in Preferences / General / Editors / Text Editors / Annotations / Errors. make sure all checkboxes are checked.

Note: My answer refers to the original question asked before it was edited, which mentioned an IOException instead of an IllegalArgumentException.

这篇关于如何使Eclipse中有误申报异常时,不抓?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 09:36