just seeking some advice here for the sake of best practices.
I have a boolean method that checks for a certain condition for each element of an array. The array parameter cannot be null nor contains null values, otherwise it wouldn't make sense to return either true or false.
Best practices states that in the event of an invalid argument being passed to a method, an ArgumentException (or derived) should be thrown. The method will throw a ArgumentNullException if the array parameter is null. However, I'm not so sure on what I should throw for an empty array or an array that contains null values.
My initial thought was to throw a plain ArgumentException with a message explaining the nature of the problem, but a colleague suggested that I'd throw an ArgumentOutOfRangeException instead.
I usually think of ArgumentOutOfRangeException as something that says "too high" or "too low". My colleague seems to believe it can also stand for "not enough" and "something missing".
Is he right? Or should I follow my first idea and throw ArgumentException?
MSDN states that you should throw ArgumentOutOfRangeException for cases where arguments are NOT null. So that is not an appropriate exception type to throw here.
You mentioned that you also want to check the array for being empty. If you do that, then throwing ArgumentNullException is not appropriate either.
That leaves you with ArgumentException.