#include #include #include using namespace std; class foundation { public: ~foundation() {cerr << "destruct the foundation\n";} }; class walls { public: ~walls() {cerr << "destruct the walls\n";} }; class roof { public: ~roof() {cerr << "destruct the roof\n";} }; //Data types of the exceptions: class trivial {}; //handling this requires the destruction of only the roof class medium {}; //requires destruction of roof and walls class severe {}; //requires destruction of roof, walls, and foundations void f() throw (severe); void g() throw (severe, medium); void h() throw (severe, medium, trivial); int main() { srand(static_cast(time(0))); try { f(); } catch (severe) { cerr << "main caught a severe exception.\n"; return EXIT_FAILURE; } return EXIT_SUCCESS; } void f() throw (severe) { foundation found; try { g(); } catch (medium) { cerr << "f caught a medium exception.\n"; } } void g() throw (severe, medium) { walls w; try { h(); } catch (trivial) { cerr << "g caught a trivial exception.\n"; } } void h() throw (severe, medium, trivial) { roof r; switch (rand() % 3) { case 0: throw trivial(); break; //this statement currently unnecessary case 1: throw medium(); break; case 2: throw severe(); break; default: break; } }