"You should throw an exception that matches the class name." Previously I had made a Date class and a Time class. They each throw InvalidDateException and InvalidTimeException and also work as intended. Currently they are part of a project with classes including Patient, Doctor, etc. These are an extension of an abstract Patient class. Each of these classes needs to only throw exceptions matching their class name. For example, a Patient object is instantiated or set to have an empty firstName, or a dateOfBirth that does not exist. It should throw InvalidPatientException and not InvalidDateException or InvalidPersonException.
public void setDOB(String dateOfBirth) throws InvalidPersonException {
try{
Date date=new Date(dateOfBirth);
this.dateOfBirth=date.getDate();
}
catch(InvalidDateException x) {
throw new InvalidPersonException("Invalid Date of Birth: <"+dateOfBirth+"- ");
}
Any knowledge about what I am trying to do or a reference would help. I'm new to exceptions.