I am using this method to determine whether the input string from a TextField in javafx has this pattern AB123CD with the pattern ("\D{2}\d{3}\D{2}") I am using a try catch enclosure, which catches a (hand)thrown PatternSyntaxException. I am asking this, because the PatternSyntaxException uses a String String Integer constructor, showing the exception like: error at index int ^ or something like that My problem is that I can't figure out how to get the right index to put in the constructor, or whether I can use any other Exception in replacement
This is the part of the code:
try {
if(!tfTarga.getText().matches("\\D{2}\\d{3}\\D{2}"))
throw new PatternSyntaxException(tfTarga.getText(), tfTarga.getText(), 0);
else {
this.olCCar.add(new CCar(new ContractCars(new Contract(this.comboCont.getValue()), this.tfTarga.getText(), LocalDate.now(), Integer.parseInt(this.tfPrezzo.getText()))));
this.tfTarga.setText("");
this.tfPrezzo.setText("");
}
} catch (PatternSyntaxException e) {
alert("Error", "Format Error", e.getLocalizedMessage());
}
Aucun commentaire:
Enregistrer un commentaire