org.sonar.l10n.java.rules.squid.RedundantThrowsDeclarationCheck.html Maven / Gradle / Ivy
An exception in a throws
declaration in Java is superfluous if it is:
- listed multiple times
- a subclass of another listed exception
- a
RuntimeException
, or one of its descendants
- completely unnecessary because the declared exception type cannot actually be thrown
Noncompliant Code Example
void foo() throws MyException, MyException {} // Noncompliant; should be listed once
void bar() throws Throwable, Exception {} // Noncompliant; Exception is a subclass of Throwable
void baz() throws RuntimeException {} // Noncompliant; RuntimeException can always be thrown
Compliant Solution
void foo() throws MyException {}
void bar() throws Throwable {}
void baz() {}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy