Back to Intellij Community

ExceptionFromCatchWhichDoesntWrap

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

2025.3-rc-2924 B
Original Source

Reports exceptions that are thrown from inside catch blocks but do not "wrap" the caught exception.

When an exception is thrown in response to an exception, wrapping the initial exception prevents losing valuable context information, such as stack frames and line numbers.

Example:

...
  catch (IOException e) {
    closeAllConnections();
    throw new ConnectException("Connection problem."); // warning: 'throw' inside 'catch' block ignores the caught exception 'e'
  }

Configure the inspection:

  • Use the Ignore if result of exception method call is used option to indicate whether the inspection should ignore exceptions whose argument is the result of a method call on the original exception, such as getMessage().
  • Use the Ignore if thrown exception cannot wrap an exception option to ignore throw statements that throw exceptions without a constructor that accepts a Throwable cause.