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

Try and Catch Q2!  RSS feed

 
Sam Bluesman
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I now have this code and for some reason it does not do what I want it to do:



It works fine if I press a letter key on the keyboard and the exception if thrown and the request to enter either 1 or 2 is repeated.

However, If i then press, say, 3 i am promted again, but if i then press a letter on the keyboard and press enter, then the user is promted "Please enter an integer", i.e. the next exception (e3) is thrown, rather than the current exception (e2), "Please enter 1 or 2".

What is going on here?

Cheers
[ March 26, 2006: Message edited by: Sam Bluesman ]
 
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
When you press 3 NOM is set to 3. It's not zero, so the loop terminates.

The catch block could set NOM back to 0, or the while could say "while (NOM != 1 && NOM != 2)".
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!