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.showInputDialo g(null, "Please Enter The Assigment Grade For The Student" );
try {
assignment1S[i] = Double.parseDouble( assignment1 );
} catch(NumberFormatExceptio n e){
JOptionPane.showMessageDia log( null, "You did not enter a number, please try again.");
valid=true;
}
if ((assignment1S[i] < 0) || (assignment1S[i] > 100))
JOptionPane.showMessageDia log( null, "Please enter a number between 0 and 100.");
} while ((assignment1S[i] < 0) || (assignment1S[i] > 100));
BJ
do {
valid=false;
assignment1 = JOptionPane.showInputDialo
try {
assignment1S[i] = Double.parseDouble( assignment1 );
} catch(NumberFormatExceptio
JOptionPane.showMessageDia
valid=true;
}
if ((assignment1S[i] < 0) || (assignment1S[i] > 100))
JOptionPane.showMessageDia
} while ((assignment1S[i] < 0) || (assignment1S[i] > 100));
Just reset focus back to the control in question.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the assistance. I see where I made my error.
BJ
BJ
Glad to help.