home *** CD-ROM | disk | FTP | other *** search
- // Chap25_1.cpp
- #include <iostream.h>
- 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;
- }
-