I'm trying to write a code for exception. If the input does not match with the pattern below (this is just example) it will throw an exception message.
8454T3477-90
This is the code that I came up with. However, I'm not sure if this is the right patter...
public void setLegalDescription(String legalDescription) throws MyInvalidLegalDescriptionException
{
String valid = ("[0-9999][A-Z][0-9999]-[0-99]");
if (!legalDescription.matches(valid))
{
//throw new MyInvalidLegalDescriptionException("Invalid format! Should be " + "e.g 4050F8335-14");
}
this.legalDescription = legalDescription;
}