IllegalArgumentException is an unchecked exception. javac does not keep track of where it might be thrown. So the rule that a catch block for an exception that will never be thrown is an unreachable statement is unenforcable for unchecked exceptions.
Mike Gershman
SCJP 1.4, SCWCD in process
Edwin Dalorzo
Ranch Hand
Joined: Dec 31, 2004
Posts: 961
posted
0
This code actually does not produce any compile-time error:
Yes, there is the rule that a catch clause should not be completely shadowed by a preceding catch clause.
There is also a rule against unreachable statements. One such case is a catch clause specifying an exception that will never be thrown in the associated try block. javac enforces this for catch clauses specifying checked exceptions like IOException and InterruptedException. However, javac does not verify that unchecked exceptions like IllegalArgumentException or mixed exceptions like Exception can actually be thrown in the associated try block.