问题
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