Can I set eclipse to show a warning if RuntimeException is not handled?

1.2k Views Asked by At

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(); ?

2

There are 2 best solutions below

0
On BEST ANSWER

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.

0
On

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.