All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.java.rules.squid.RedundantThrowsDeclarationCheck.html Maven / Gradle / Ivy

There is a newer version: 8.6.0.37351
Show newest version

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