• 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
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Try and Catch Q2!

 
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)".
 
There's a hole in the bucket, dear Liza, dear Liza, a hole in the bucket, dear liza, a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic