Ok so I am trying to build a exception handler, and I can't for the life of me, figure out why its not working! I did more or less the exact same thing on a previous assignment and it worked fine.
So this is the exception handler class
package cst8284.asgmt3.scheduler;
public class BadAppointmentDataException extends RuntimeException{
private static final long serialVersionUID = 1L;
private String Description;
public String getDescription() {
return Description;
}
public void setDescription(String Description) {
this.Description = Description;
}
public BadAppointmentDataException(String m, String e) {
super(m);
this.setDescription(e);
}
public BadAppointmentDataException() {
this("Please Try Again","Bad Data Entered");
}
}
and then to test a string I used a method that creates a pattern
private static boolean testPhone(String p) {
Pattern pnum = Pattern.compile("\\d{3}\\-\\d{3}\\-\\d{4}");
Matcher m = pnum.matcher(p);
boolean b = m.matches();
return b;
}
It is making sure a phone number is entered correctly. I've tested the method and it works fine.
BUT, when I do and if statement such as
if (!testPhone(phoneNumber)){
throw new BadAppointmentDataException("why doesn't this","work");
}
I get a unhandled exception error and it just crashes pointing to the line that calls the BadAppointmentDataException
as the failure!