How to make Eclipse with to report error when declared exception is not caught?

北战南征 提交于 2019-12-13 02:56:58

问题


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 {}

回答1:


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.



来源:https://stackoverflow.com/questions/21038779/how-to-make-eclipse-with-to-report-error-when-declared-exception-is-not-caught

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!