I am writing a method to find the Xth largest entry in a list. The header is
<T extends Comparable<T>> T max(List<T> list, int rank) {...}
where rank is which place to find the max, (i.e. 0 is max, 1 is 2nd largest, ..., list.size() -1 is the min).
What Exception should I throw if a rank parameter is given that is >= list.size()? Is it an IndexOutOfBoundsException, because you are requesting the value of an index that is out of bounds, or would it be an IllegalArgumentException, because the IndexOutOfBoundsExeption is caused by the given parameters?
(I read this on when to use an IllegalArgumentException, but it just further confused me. In my case, the rank input could be user input or from a different place in the program, so I am not sure which is applicable.)