I have public method add(String)
that calls private method inspectSequence(String)
to check whether String valid or not.
This method returns array if passed String
is valid, if it's invalid then method throws IllegalArgumentException
the code is next
public void add(String sequence) throws IllegalArgumentException{
inspectSequence(sequence);
}
private int[] inspectSequence(String sequence){
int[] array;
//some actions
if(<some condition>) throw new IllegalArgumentException("description");
return array;
}
So in cases, when invalid String
were passed to add
method output will be next:
java.lang.IllegalArgumentException: description
at inspectSequence
at add
But I don't want user to know about private inspectSequence
method because this is realization detail, right?
So what I can do in that case? Is it a good idea to throw unchecked exception here?
And is a good idea to throw exception inside inspectSequence
method or I should return null
when supplied String
isn't valid and then check returned result in add
method and depending on it throw or not throw exception?