Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

try and catch question  RSS feed

 
Sam Bluesman
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following code:



Bascially, if the user does not type an integer (e.g. the user types a letter on the keyboard) then program will prompt the user to do so, but this happens only once. I want it to repeat doing the exception handling above until the user types in an integer. What do i need to do to the code?

Cheers
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Put the whole thing into a "while (user hasn't successfully entered a value)" loop. If you removed the assignment to NOM from the catch block, you could just use "while (NOM == null)".
 
Sam Bluesman
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah I c. Thanks for that. And thanks for your help on an earlier post. Much appreciated!

SB
[ March 26, 2006: Message edited by: Sam Bluesman ]
 
Sam Bluesman
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actaully, as NOM will be an integer it will have to be 0, rather than null. Right? Also, it says NOM might not have been initialised...
 
Sam Bluesman
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DW. Sorted!

Thanks again
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!