I have some code code splits a string (user input) into an array and passes the elements of that array into a method as arguments. If the array does not have enough elements an ArrayIndexOutOfBoundsException is thrown automatically. However, this is an unchecked exception, and since this is a problem with incorrect input from the user I could instead check for this condition beforehand and throw a checked exception.
So, I have a couple of questions:
- Would it be better form to handle the unchecked exception or throw a checked one?
- If I do throw a checked exception, should I use IllegalArgumentException? My understanding is that it is for illegal argument types, not an illegal number of arguments.
Thanks.