This week's giveaway is in the Spring forum.
We're giving away four copies of Microservices Testing (Live Project) and have Chris Love & Andres Sacco on-line!
See this thread for details.
Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

looping until user input is correct

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 904
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic