home *** CD-ROM | disk | FTP | other *** search
/ C++ for Dummies (3rd Edition) / C_FD.iso / CHAP25 / CHAP25_1.CPP
C/C++ Source or Header  |  1996-09-02  |  867b  |  64 lines

  1. // Chap25_1.cpp
  2. #include <iostream.h>
  3. class Obj
  4. {
  5.   public:
  6.     Obj(char c)
  7.     {
  8.         label = c;
  9.         cout << "Constructing object " << label << endl;
  10.     }
  11.    ~Obj()
  12.     {
  13.         cout << "Destructing object "  << label << endl;
  14.     }
  15.  
  16.   protected:
  17.     char label;
  18. };
  19.  
  20. void f1();
  21. void f2();
  22.  
  23. int main(int, char*[])
  24. {
  25.     Obj a('a');
  26.     try
  27.     {
  28.         Obj b('b');
  29.         f1();
  30.     }
  31.     catch(float f)
  32.     {
  33.         cout << "Float catch" << endl;
  34.     }
  35.     catch(int i)
  36.     {
  37.         cout << "Int catch" << endl;
  38.     }
  39.     catch(...)
  40.     {
  41.         cout << "Generic catch" << endl;
  42.     }
  43.     return 0; 
  44. }
  45.  
  46. void f1()
  47. {
  48.     try
  49.     {
  50.         Obj c('c');
  51.         f2();
  52.     }
  53.     catch(char* pMsg)
  54.     {
  55.         cout << "String catch" << endl;
  56.     }
  57. }
  58.  
  59. void f2()
  60. {
  61.     Obj d('d');
  62.     throw 10;
  63. }
  64.