home *** CD-ROM | disk | FTP | other *** search
/ Microsoftware Monthly 19…2 Programming Power Tools / MASO9512.ISO / cpptutor / cpptutor.arj / EXAMPLES / EX1602.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-24  |  1.2 KB  |  41 lines

  1. // \EXAMPLES\EX1602.CPP
  2.  
  3. //----------------------------------------------------------
  4. //  Exception handling is supported only by
  5. //                            the IBM C Set++ Compiler
  6. //  This example does not work in Borland Turbo C++
  7. //                          or in Microsoft Visual C++
  8. //----------------------------------------------------------
  9. //  To run this program on an OS/2 machine:
  10. //                      move to an OS/2 window
  11. //              [type]  cd:\EXAMPLES\EX1602I
  12. //                      where cd: is the drive of the CD-ROM
  13. //----------------------------------------------------------
  14.  
  15. #include <iostream.h>
  16.  
  17. //
  18. // This is an example of nested try blocks
  19. //
  20. void main()
  21. {
  22.   try                     // outer try block
  23.   {
  24.      try                  // nested try block
  25.      {
  26.      float x = 1;
  27.         throw( x);        // something went wrong
  28.      }
  29.      catch( char y)       // nested try block exception handler
  30.      {
  31.        cout << "The nested eception handler caught the exception"
  32.             << endl;
  33.      }
  34.   }
  35.   catch( float x)         // outer try block exception handler
  36.   {
  37.      cout << "The outer exception handler caught the exception"
  38.           << endl;
  39.   }
  40. }
  41.