J.V · Java 25 practice question
A developer writes a multi-catch clause: catch (IllegalArgumentException | IllegalStateException e). According to the JLS, what is the declared type of the exception parameter e?
Check answer and explanation
Correct answer: The least upper bound lub(IllegalArgumentException, IllegalStateException)
Explanation
For an exception parameter whose type is a union D1 | D2 | ... | Dn, the declared type is the least upper bound lub(D1, D2, ..., Dn), which here is RuntimeException.
Common trap
The declared type is not hardcoded to Exception; it is computed as the least upper bound of the specific alternatives. The parameter is typed to the least upper bound of the exception classes, not Object, so Throwable methods like getMessage() are directly accessible.
Source: JLS SE 25 §14.20. The try statement
Checked against the cited text on 2026-11-25.