Actually, I think I throw all of these as IAEs. ... The reality is that the state version, throwing IllegalStateException, is hardly ever usedPerhaps by you. But speak for yourself! :)
I actually use IllegalStateException rather often, and UnsupportedOperation on occasion. Clearly, IAE would be totally inappropriate from, say, the no-args remove() method on an iterator:
public void remove()
{
if(curElem == null)
throw new IllegalArgumentException("iterator is already past end of collection");
// Above makes no sense: What illegal argument?!
...
}
However, IAE is by far the most common, and it is almost always the case that IAE is appropriate for validation. So I think we could both agree that methods on Validate could be explicitly designed for checking arguments, and throw IAE. That certainly seems reasonable to me.
The only danger here is that while while the code above is quite obviously wrong, the following code has exactly the same problem, but it's much less obvious:
public void remove()
{
Validator.isNotNull(curElem, "iterator is already past end of collection");
...
}
That's why it would probably be best to choose a method name which made it clear that the method is for argument validation, not null checking in general.
Cheers,
Paul
--
To unsubscribe, e-mail: <mailto:commons-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@;jakarta.apache.org>
