#include #include using namespace std; int main() { cin.exceptions(ios_base::badbit | ios_base::failbit | ios_base::eofbit); int i; //uninitialized variable cout << "Please input an integer: "; try { cin >> i; } catch (const ios_base::failure& fail) { cerr << "caught ios_base::failure exception " << fail.what() << "\n"; if (cin.eof()) { cerr << "encountered end of input\n"; } else if (cin.bad()) { cerr << "couldn't input characters from outside world\n"; } else if (cin.fail()) { cerr << "the first non-whitespace characters read\n" "from input were not one or more consecutive\n" "digits optionally preceded by a minus sign\n"; } else { cerr << "unknown error\n"; } return EXIT_FAILURE; } cout << "The number was " << i << ".\n"; return EXIT_SUCCESS; }