Hey there so in my class I had written this:
public void setId(String id) { ...
if (id.matches("[a-zA-Z]{3}-\\d{4}")) {
this.id = id;
} else { // id is invalid: exception occurs
throw new IllegalArgumentException("Inventory ID must be in the "
+ "form of ABC-1234");
}
}
then in my main program I did this:
while (idLoopTrigger == true) {
try {
System.out.println("Please enter id: ");
id = in.nextLine();
if (id.matches("[a-zA-Z]{3}-\\d{4}")) {
idLoopTrigger = false;
}
} catch (Exception ex) {
//print this error message out
System.out.println(ex.getMessage());
}
}
So it will loop until the user inputs the correct info but it won't display the exception message from my class. Thoughts?