Results 1 to 2 of 2

Thread: try/catch problem yet again

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member GamerMax5's Avatar
    Join Date
    Nov 2004
    Location
    United States
    Posts
    388

    Question 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.
    Only those who try will become.

    Find me on identi.ca

    Twitter @gfmartin05

    Linux Wrap

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width