https://rentry.org/PPP2_p151 ⎗ ✓ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23// Code derived from Stroustrup's PPP2 book // § 5.6.3 Bad input // -and beginning on p 151 #include <iostream> #include <stdexcept> using std::cerr; using std::runtime_error; void error(const char* s) { throw runtime_error(s); } int main() try { // . . . our program . . . return 0; // 0 indicates success } catch (runtime_error& e) { cerr << "runtime error: " << e.what() << '\n'; // keep_window_open(); return 1; // 1 indicates failure } build & run: g++ -std=c++20 -O2 -Wall -pedantic ./ch_05/main_p151.cpp && ./a.out sauce: Bjarne Stroustrup's PPP2 textbook /robowaifu/'s official C++ learning textbook thread Prev • Up • Next