That would have been caught first, but there would have been many other exceptions. You should not catch more than you really want.
The second is better if you really need to catch it ... but usually this indicates an error in the calling code. Sometimes this is the case of another method, above which its arguments are not checked, etc. In an ideal world, anytime an IllegalArgumentException thrown, there must be a way so that the caller can check the value before passing it or call the version that fails in a non-standard way (for example, the TryParse pattern in .NET, which is admittedly more complicated in Java without out parameters). This is not always the case, but whenever you get an IllegalArgumentException , it is worth checking if this can be avoided by checking the values ββbefore calling the method.
Jon skeet
source share