Is it good way of asking for a number? Should that function return 0 if there is an error?
private int getNumberDialog(String message) {
try {
String resultInString = JOptionPane.showInputDialog(message);
int result = Integer.parseInt(resultInString);
return result;
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "You didn't gave a number");
}
return 0;
}
public void playForMeNrTimes() { int howManyTimes = getNumberDialog("How many times?"); game.playForMeNrTimes(howManyTimes); }
I just want to know if handling an exception this way is ok \$\endgroup\$