3

I have the following code:

public static void main(String[] args)
{
    willItThrowException();
}

private static void willItThrowException() throws RuntimeException
{
    throw new RuntimeException();
}

Is there any configuration of eclipse that can show a warning/error on uncaught runtime exception that is declared in method declaration but not catched in line of willItThrowException(); ?

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
oshai
  • 14,865
  • 26
  • 84
  • 140
  • yes if eclipse shows a warning then its checked exception rather than a Runtime as JB said. – amod Oct 18 '11 at 10:00

2 Answers2

3

If it should generate a warning, then it means that your runtime exception should not be a runtime exception, but a checked exception. Runtime exceptions are not meant to be caught (in the general case). If they happen, it means that you have a bug in your program. Catching the exception won't fix the bug.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
1

Not that I'm aware of, and I can't find one. Catching runtime exceptions is not always a good choice though. And you will get tons of warnings about catching IllegalArgumentException and NullPointerException. Runtime exceptions are usually meant not to be recoverable from.

kryger
  • 12,906
  • 8
  • 44
  • 65
Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140