isiauna2009
asked on
validate date not null and throw exception
Hello Experts,
I am totally lost. I am trying to validate a perameter which is (GregorianCalender, date ) the validation must not be null.
I was using an if statement and used (date != null). I have to throw an illegalArugmrnt and I used {
IllegalArgumentException exception = new IllegalArgumentException ();
throw exception;
}
My test keeps failing, it is my code. How can I Validate that the given parameter date is not null.
What am I doing wrong?
I am totally lost. I am trying to validate a perameter which is (GregorianCalender, date ) the validation must not be null.
I was using an if statement and used (date != null). I have to throw an illegalArugmrnt and I used {
IllegalArgumentException exception = new IllegalArgumentException ();
throw exception;
}
My test keeps failing, it is my code. How can I Validate that the given parameter date is not null.
What am I doing wrong?
Probably need a bit more of your code. To see if a parameter is not null is what you've got. You can see if (object == null) and handle it that way or check to make sure its != null.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>
Shouldn't you be saying:
..
Instead of:
>>
Absolutely ;)
Shouldn't you be saying:
..
Instead of:
>>
Absolutely ;)
There's actually no reason you need to catch it in a real program. Passing null would be an error and runtime would deal with it.
> Shouldn't you be saying:
good pickup :)
I better get some coffee
good pickup :)
I better get some coffee
Hm, interesting discussion :-)
May be you have catched the exception in the same method, instead of declare the method in this way:
...validate(Date dt) throws IllegalArgumentException {
May be you have catched the exception in the same method, instead of declare the method in this way:
...validate(Date dt) throws IllegalArgumentException {
You might also like to throw for dates that are out of range
throw new IllegalArgumentException("
}