try/catch problem yet again
I've almost got this... I hope. :)
Okay here is the peice of code I have a question about:
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);
}
}
tryAgain is set to true BTW.
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?
Re: try/catch problem yet again
your code doesn't make any sense.
the same code that fires the exception exists inside the exception handler, so if it happened again java will catch it, not your prog, that's why it exits