#include #include #include //for class string and the function stoi using namespace std; int main() { const string s {"l234"}; //or try "2147483648", just barely too big try { const int i {stoi(s)}; cout << "i = " << i << "\n"; } catch (const invalid_argument& ex) { cerr << "Not a valid integer " << ex.what() << "\n"; return EXIT_FAILURE; } catch (const out_of_range& ex) { cerr << "Value out of range " << ex.what() << "\n"; return EXIT_FAILURE; } catch (...) { //none of the above cerr << "Unexpected type of exception thrown.\n"; return EXIT_FAILURE; } return EXIT_SUCCESS; }