What is relatively more true? As Kirk says, it depends. Sometimes a null makes logical sense, and sometimes an exception is better suited if the default is not reasonable. One thing I'm trying to do is think that βis GetCurrentItem causing a logical failure or a safe thing?β
If this is not a GetCurrentItem call when it is not, then throwing an exception is the right course. For example, if your collection has the HasCurrent or IsEmpty property, where someone can check the result before calling GetCurrentItem , then they should "know better." But if the current null element is the right logical way to use your class, then by all means its design. In any case, I would document the behavior in the code comments so that users are aware of the expected behavior.
I will say this, however, by throwing an ArgumentOutOfRange exception, there may be bleeding implementation details. That is, if the user of this class does not know that the internal structure is an array or List<T> , then do not deflate this exception, but understand it, wrap it and throw a more significant one (user-defined or something like InvalidOperationException ).
Since they really don't pass the argument directly, they get an ArgumentOutOfRange exception, which can be confusing :-)
James Michael Hare
source share