home *** CD-ROM | disk | FTP | other *** search
- // \EXAMPLES\EX1608.CPP
-
- //----------------------------------------------------------
- // Exception handling is supported only by
- // the IBM C Set++ Compiler
- // This example does not work in Borland Turbo C++
- // or in Microsoft Visual C++
- //----------------------------------------------------------
- // To run this program on an OS/2 machine:
- // move to an OS/2 window
- // [type] cd:\EXAMPLES\EX1608I
- // where cd: is the drive of the CD-ROM
- //----------------------------------------------------------
-
- #include <iostream.h>
- #include <string.h>
- #include <stdlib.h>
-
- //
- // This is example illustrates uncaught exceptions
- //
-
- //
- // divides x by y, if y is 0 divide throws an exception
- //
- long divide( long x, long y)
- {
- if (y ==0)
- {
- cout << "Throwing a long exception." << endl;
- throw (y);
- }
- return (x/y);
- }
-
- main()
- {
- try
- {
- int z = divide( 1, 0); // divide throws a long exception
- }
- //
- // There is no long exception handler, the program terminates
- //
- catch (float)
- {
- cout << "This won't get printed.";
- }
- }
-