Back to Intellij Community

MultiCatchCanBeSplit

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

2025.3-rc-2434 B
Original Source

Reports multi-catch sections and suggests splitting them into separate catch blocks.

Example:

try {
    int i = getIndex();
  } catch (NullPointerException|IndexOutOfBoundsException e) {
    e.printStackTrace();
  }

After the quick-fix is applied:

try {
    int i = getIndex();
  } catch (NullPointerException e) {
    e.printStackTrace();
  } catch (IndexOutOfBoundsException e) {
    e.printStackTrace();
  }