Back to Intellij Community

ThrowFromFinallyBlock

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

2025.3-rc-2569 B
Original Source

Reports throw statements inside finally blocks. While occasionally intended, such throw statements can hide exceptions thrown from the try and catch blocks, thereby complicating the debugging process.

Example:

class Fascinating {
    void doTask(Task t) {
      try {
        t.activity();
      } finally {
        if (!t.finish()) {
          throw new IllegalStateException();
        }
      }
    }
  }

Use the Warn everywhere declared exceptions may be thrown option to warn on method calls to methods that declare exceptions as well.