An exception in a throws
declaration in Java is redundant if:
RuntimeException
, or one of its descendantsThe following code:
void foo() throws MyException, MyException {} // Non-Compliant - should be listed once void bar() throws Throwable, Exception {} // Non-Compliant - Exception is a subclass of Throwable void baz() throws RuntimeException {} // Non-Compliant - RuntimeException can always be thrown
should be refactored into:
void foo() throws MyException {} // Compliant void bar() throws Throwable {} // Compliant void baz() {} // Compliant