#include #include #include #include using namespace std; class ExpectFail { public: string message; ExpectFail(string m) : message(m) {}; }; void expect(bool test, string msg) { if(!test) { throw ExpectFail("Expectation failed."); } } int area(int length, int width) { expect(length > 0 && width > 0, "Bad area given."); return length * width; } int main() { vector numbers; try { numbers.push_back(100); numbers.push_back(-100); cout << "Area " << area(numbers.at(1), 100) << "\n"; return 0; } catch(out_of_range &e) { cout << "Out of range ERROR: " << e.what() << "\n"; return 2; } catch(...) { cout << "Exception: something went wrong\n"; return 3; } }