Module 2 Milestone 2 InvalidInputDate

Build fails in InvalidInputDate. I read a few threads and understood why the build failed. but idk how to resolve it. i tried using try and catch block but after that the output that i got was not correct. Can someone give some hints or some useful links to refer to?

Check it here.

Try checking if the input date is more than the end date and throwing some error if that is the case.

I read this thread. But if i try implementing a bit using if, else try and catch the output becomes wrong.

don’t use try catch block. you can use throw keyword and throw the exception you want.

How should i throw this error? Through if else or should i include the Exception in throws while declaring the function?

try using “if” with some condition including dates

check the format of the date you’re inputting. Also check if the date itself is correct. read the todos to know what the start and end date should be

Hey Maybe there is testcase which is checking for that enddate is greater then startdate so be careful about that add a checking statement for that

Just see the test file , it need an instance of RuntimeException to be thrown when invalid dates condition is met. Just throw the exception on invalid dates case.
In java we can throw an exception inside if block like this :
if (Condition) {
thrown new ExceptionName();
Hope this link helps :
Also read this :

To avoid this problem without using the try-catch/ throw use this:-
and also if you are facing 0 year difference:-

1 Like

Thank you so much everyone! Found the way :smiley:

How did you solve the problem?
I am throwing runtime exception if dates are invalid but the test is still failing

Has the issue been solved? Did the Build fail or did the assessment fail?

1 Like

The problem was solved.

1 Like