Inspectopedia Help

Overly broad 'throws' clause

Reports throws clauses with exceptions that are more generic than the exceptions that the method actually throws.

Example:

public void createFile() throws Exception { // warning: 'throws Exception' is too broad, masking exception 'IOException' File file = new File("pathToFile"); file.createNewFile(); }

After the quick-fix is applied:

public void createFile() throws IOException { File file = new File("pathToFile"); file.createNewFile(); }

Configure the inspection:

  • Use the Maximum number of hidden exceptions to warn field to ignore exceptions, that hide a larger number of other exceptions than specified.

  • Use the Only warn on RuntimeException, Exception, Error or Throwable option to have this inspection warn only on the most generic exceptions.

  • Use the Ignore exceptions declared on methods overriding a library method option to ignore overly broad throws clauses in methods that override a library method.

  • Use the Ignore exceptions which hide others but are themselves thrown option to ignore any exceptions that hide other exceptions but still may be thrown from the method body and thus are technically not overly broad.

Inspection options

Option

Type

Default

Maximum number of hidden exceptions to report

Number

10

Only warn on RuntimeException, Exception, Error or Throwable

Checkbox

false

Ignore exceptions declared on methods overriding a library method

Checkbox

false

Ignore exceptions which hide others but are themselves thrown

Checkbox

false

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3

Plugin:

Java, 233.SNAPSHOT

Last modified: 13 July 2023