Create class TestBook, and create test cases to test class Book
Do not handle any exception in this phase, just pass them to the caller method.
Does the above instruction mean my tester class, TestBook should have it's main method "throws ParseException" and when I run my program with an "error" this shouldn't crash instead it should pass the exception to...?
public class TestBook{
public static Book directory=new Book(); //Book contains an arraylist of dates
public static void main(String[] args) throws ParseException {
directory.addApt("01-04-1996","testdate");
//this will create an instance of a Apt and is in the INCORRECT format.
}
The addApt method from the Book class looks like this:
String[] dates=date.split("-");
if(dates[0]!=2)
throw new ParseException("incorrect format day should be in numbers,2);
if(dates[0]!=3)
throw new ParseException("incorrect format month should be in letters,2);
if(dates[0]!=4)
throw new ParseException("incorrect format year should be in numbers,2);
Apt newAppt=new Apt=(date,type);
When I run this, i get an error message: Exception in thread "main" java.text.ParseException: incorrect format, month should be in letters.
But My question is why this shows up, since I am throwing it, why is it handling it like this? i guess I am confused about the throw(s) vs. try/catch..