Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

Exception handeling closes my program

$
0
0

Brand new to C++

cout << "Hello World!" << endl;

int x = 0;

cout << "Enter your favorite number: ";

	
try
{
    cin >> x;
}
catch (int e)
{
    cout << "Hey dummy, enter a number!" << endl;
}

cout << x << "? That's a pretty small number. \nI bet that's the highest you can count." << endl;

string mystring;

// Made possible by <string>
cout << "Tell us your name: ";
getline (cin, mystring);
cout << "Hello " << mystring << endl;

If I delete the following code my program runs fine. So what's wrong with my try/catch statement?

try
{
    cin >> x;
}
catch (int e)
{
    cout << "Hey dummy, enter a number!" << endl;
}


-Nothing to see. Move along.




Viewing all articles
Browse latest Browse all 15302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>