|
-
Nov 17th, 2005, 04:22 PM
#1
Thread Starter
Hyperactive Member
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?
Last edited by GamerMax5; Nov 17th, 2005 at 04:46 PM.
-
Nov 18th, 2005, 07:13 AM
#2
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
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|