J.V · Java 25 practice question

What happens when a developer compiles this Java 25 program?

void main() {
  try {
    throw new IllegalArgumentException();
  } catch (IllegalArgumentException | IllegalStateException e) {
    e = new RuntimeException();
  }
}
Choose one answer
Check answer and explanation

Correct answer: It fails to compile because the multi-catch exception parameter e is implicitly final

Explanation

An exception parameter declared in a multi-catch clause is implicitly final even without the final modifier, so reassigning e inside the catch block causes a compile-time error.

Common trap

While a single-type catch parameter can be reassigned if not marked final, a multi-catch parameter is always implicitly final. Adding RuntimeException would not make e assignable and would also violate the multi-catch subtype rule.

Source: JLS SE 25 §14.20. The try statement
Checked against the cited text on 2026-11-25.

Report an error in this question