I've almost got this... I hope.![]()
Okay here is the peice of code I have a question about:
tryAgain is set to true BTW.Code:while (tryAgain) { try { orderTotal = Double.parseDouble(inputString); while (orderTotal == 0) { inputString = JOptionPane.showInputDialog("Invalid order total \n" + "Please enter a correct order total: "); orderTotal = Double.parseDouble(inputString); } tryAgain = false; } catch (NumberFormatException e) { inputString = JOptionPane.showInputDialog("Invalid order amount. \n" + "Please enter a valid amount: "); orderTotal = Double.parseDouble(inputString); } catch (NullPointerException e) { inputString = JOptionPane.showInputDialog("Invalid order amount. \n" + "Please enter a valid amount: "); orderTotal = Double.parseDouble(inputString); } }
Without the second catch for the NullPointerException, it keeps looping until an appropriate value is entered. However with the second catch, it doesn't loop. If you press the Cancel button twice, it exits the program. Why is it doing this?




Reply With Quote