Sign in to follow this  
slaker

help on some kind of exception handling

Recommended Posts

let`s say i have this code in visual c++ 2003 [CODE] #include <iostream> using namespace std; void main() { int var; while(1) { cin >> var; if (var==99) { cout << "99 entered"; } } } [/CODE] 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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this