What we have to print in console when the Date is invalid?

I have verified that the date is invalid or not and also throws a run time exception if the date is invalid and when it is catch then i have returned null.Do we have to print anything when the Date is invalid.I have done the following work:

LocalDated d1=getPurchaseDate();
LocalDate d2=from args[1]’

if(d1.comapreTo(d2) is invalid){
throw RunTimeException();

}catch(Exception e){
return null;

It is giving me an assertion error when build.

I don’t think you need to explicitly print anything in console. I didn’t when I did this module.

Can you tell in which file and line the error is coming?

The error is coming from ModuleTwoTest.java.Do I have to explicitly mention catch for each type of exception like RunTime ,NullPoint or just write Exception e for all

Do one thing. Go to the test file and the specified line number. If it’s not empty, you can see what values they are passing and what’s the output they expect. Then run a debug test and see what value your code returns by adding a break point. That’s help you get started in removing the error.

Can you tell me where is the output they expect from us from looking at this test case.I am not able to understand.I am stuck at this issue form past 2 days.

So basically, the first part before the comma is the expected output and after the comma they have made the call to your code and see what error it’s throwing.

1 Like

Thankyou for the help.Do we need only one catch statement or multiple catch for each error?

Also what we have to print RunTimeException in console or just return null or return EmptyList if date is invalid?

You can use mutiple catch statements if you want to catch different errors.
It is absolutely fine

1 Like

I think throwing it should be sufficient, since that’s what the test accepts.

1 Like

Depends on what errors it’s checking for. Even if you use a generic catch that catches all exceptions and throws only runtime, spot bugs will probably raise an error. So in that situation throwable works better. If the tests for multiple exceptions, then multiple catch blocks will be needed.

1 Like

Also what we have to print RunTimeException in console or just return null or return EmptyList if date is invalid? For this one?

Throwing runtime should be sufficient. It’ll automatically print the stackrace on console. And then perhaps if needed, you can add a finally block and return null, though I don’t think it’s necessary. Try it out, you have figured out of most of it and I am confident you’ll figure out the tiny remaining part.