Back to Intellij Community

BadExceptionCaught

java/java-impl/resources/inspectionDescriptions/BadExceptionCaught.html

2025.3-rc-2563 B
Original Source

Reports catch clauses that catch an inappropriate exception.

Some exceptions, for example java.lang.NullPointerException or java.lang.IllegalMonitorStateException, represent programming errors and therefore almost certainly should not be caught in production code.

Example:

try {
    return component.getMousePosition(true) != null;
  } catch (NullPointerException e) { // warning: Prohibited exception 'NullPointerException' caught
    return false;
  }

Use the Prohibited exceptions list to specify which exceptions should be reported.