Link to home
Start Free TrialLog in
Avatar of brenoby
brenoby

asked on

Try-Catch Problem

I am trying to do a try catch concerning the entering of letters.  When i enter a letter I display the message that says, you must enter a number, however my problem is that the user is not returned to the dialog box to re-enter the number.  It skips to the next dialog box.  I believe that I may have my try-catch in the wrong position or am missing one line.  Any assitance is appreciated.

BJ

  do {                
             
            valid=false;
                assignment1 = JOptionPane.showInputDialog(null, "Please Enter The Assigment Grade For The Student" );                        
                             
            try {
               
           
                assignment1S[i] = Double.parseDouble( assignment1 );
               
            } catch(NumberFormatException e){    
                     
             JOptionPane.showMessageDialog( null, "You did not enter a number, please try again.");              
               
             valid=true;
             
            }
                                       
               if ((assignment1S[i] < 0) || (assignment1S[i] > 100))
                   
                   JOptionPane.showMessageDialog( null, "Please enter a number between 0 and 100.");                  
                   
               
         
            } while ((assignment1S[i] < 0) || (assignment1S[i] > 100));
Avatar of cookre
cookre
Flag of United States of America image

Just reset focus back to the control in question.
ASKER CERTIFIED SOLUTION
Avatar of mrwad99
mrwad99
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of brenoby
brenoby

ASKER

Thanks for the assistance.  I see where I made my error.

BJ
Glad to help.