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

  1. // \EXAMPLES\EX1608.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\EX1608I
  12. //                      where cd: is the drive of the CD-ROM
  13. //----------------------------------------------------------
  14.  
  15. #include <iostream.h>
  16. #include <string.h>
  17. #include <stdlib.h>
  18.  
  19. //
  20. // This is example illustrates uncaught exceptions
  21. //
  22.  
  23. //
  24. // divides x by y, if y is 0 divide throws an exception
  25. //
  26. long divide( long x, long y)
  27. {
  28.    if (y ==0)
  29.    {
  30.       cout << "Throwing a long exception." << endl;
  31.       throw (y);
  32.    }
  33.    return (x/y);
  34. }
  35.  
  36. main()
  37. {
  38.    try
  39.    {
  40.       int z = divide( 1, 0);   // divide throws a long exception
  41.    }
  42.    //
  43.    // There is no long exception handler, the program terminates
  44.    //
  45.    catch (float)
  46.    {
  47.       cout << "This won't get printed.";
  48.    }
  49. }
  50.