// ThrowUnwind - demonstrate how objects get destructed // as the exception handler unwinds the stack #include #include // Obj - empty object class with noisy constructor // and destructor class Obj { public: Obj(char c) { label = c; cout << "Constructing object " << label << endl; } ~Obj() { cout << "Destructing object " << label << endl; } protected: char label; }; void f1(); void f2(); int main(int, char*[]) { Obj a('a'); try { Obj b('b'); f1(); } catch(float f) { cout << "Float catch" << endl; } catch(int i) { cout << "Int catch" << endl; } catch(...) { cout << "Generic catch" << endl; } return 0; } void f1() { try { Obj c('c'); f2(); } catch(char* pMsg) { cout << "String catch" << endl; } } void f2() { Obj d('d'); throw 10; }