• Post Reply Bookmark Topic Watch Topic
  • New Topic

looping until user input is correct  RSS feed

 
John Uhlig
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing a bit of code asking the user for a date of birth. I want it in the correct format. So, I have written this bit of code:


What I want to do though is modify this so that it continues to loop until the date is entered in the correct format.

My thoughts are to create enclose the try...catch inside a while loop. The loop would check to see if an exception has occured or not. If not, continue on, else loop again and ask for the date of birth.

Should I check to see if an exception has occured? For example declare a ParseException variable, then assign it the exception that is passed to the catch block - like so:


Or is there a better way to do this?

Thanks,
John
 
Svend Rost
Ranch Hand
Posts: 904
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I've got a question:

Are you working on a GUI app. or a console program?

If you are working on the GUI I would use some kind of
a listener on one of your components (button, textfield ect)
and make the test there.

If your making a console program I'd do something like:



/Svend Rost
 
John Uhlig
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is a console program at this point. We are working on an exercise where it will eventually transform into something else, but at this point it is console. Thanks for your help. The boolean makes sense.

John
 
John Uhlig
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is a console program at this point. We are working on an exercise where it will eventually transform into something else, but at this point it is console. Thanks for your help. The boolean makes sense.

John
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!