0

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 {}
Natalia
  • 783
  • 7
  • 18

1 Answers1

2

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.

Dominic
  • 4,572
  • 3
  • 25
  • 36
  • yes, I double checked and that is RuntimeException which is not reported... So I can't change that, because it's _runtime_? – Natalia Jan 10 '14 at 08:07
  • @Natalia see http://stackoverflow.com/questions/12162572/eclipse-warn-about-uncaught-error – André Stannek Jan 10 '14 at 08:09
  • 1
    @Natalia: `RuntimeException` is an unchecked exception, much like `Error` throwables. You can catch them, but the compiler will not complain if you do not because they are normally thrown for situations that the caller is not expected to or even unable to handle... – thkala Jan 10 '14 at 08:10
  • @Natalia see http://stackoverflow.com/questions/5963319/whats-the-configuration-to-notify-the-unhandled-exceptions-in-eclipse for more details – Dominic Jan 10 '14 at 08:37