Jump to content
  • Advertisement
Sign in to follow this  
slaker

help on some kind of exception handling

This topic is 4834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

let`s say i have this code in visual c++ 2003 #include <iostream> using namespace std; void main() { int var; while(1) { cin >> var; if (var==99) { cout << "99 entered"; } } } now my problem is this: if i write a char or anything else != decimal ths program breaks do you know any solve for this? i`ve tryied try-catch-trow but maybe i dont know how to use it well because it didnt solved anything 10x

Share this post


Link to post
Share on other sites
Advertisement

try {
int var;

while(1) {
cin >> var;
if (var==99) { cout << "99 entered"; }
}

} catch(...) {
// This will catch everything, however you will no longer be notified,
// so if someone can tell you the specific exception that is the better
// way to go. However you can always fall back on this.
}

Share this post


Link to post
Share on other sites
***edit
thanks for the reply but it doesnt work...
if a non decimal character is entered the program loops forever printing continously the last line printed

[Edited by - slaker on May 27, 2005 7:34:25 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!