If the indices were out of bounds, an exception would eventually be thrown but
it would fail on the first index out of bounds, giving a mis-leading message.
Checking at the beginning of the method means the error message can be
more useful.
would give IndexOutOfBoundsException: 10 despite 10 not being an argument to the method.
With this change, the user will get IllegalArgumentException: Bad row argument 15; out of bounds immediately after invocation.
If the indices were out of bounds, an exception would eventually be thrown but it would fail on the first index out of bounds, giving a mis-leading message. Checking at the beginning of the method means the error message can be more useful.
For example, the following code:
would give
IndexOutOfBoundsException: 10
despite10
not being an argument to the method. With this change, the user will getIllegalArgumentException: Bad row argument 15; out of bounds
immediately after invocation.