home *** CD-ROM | disk | FTP | other *** search
/ Using Visual C++ 4 (Special Edition) / Using_Visual_C_4_Special_Edition_QUE_1996.iso / ch13 / simple.cpp < prev    next >
C/C++ Source or Header  |  1995-09-18  |  504b  |  25 lines

  1. // Get needed include files
  2. #include <limits.h>
  3. #include <iostream.h>
  4. #include <eh.h>
  5.  
  6. unsigned short Add(unsigned short addend1, unsigned short addend2)
  7. {
  8.     unsigned long sum = addend1 + addend2;
  9.     if (sum > USHRT_MAX)
  10.         throw 1;
  11.     return (unsigned short) sum;
  12. }
  13.  
  14. void main()
  15. {
  16.     try {
  17.         unsigned short Result = Add(12345, 54321);
  18.         cout << "The answer is " << Result << "\n";
  19.     }
  20.     catch (int ErrorCode) {
  21.         cout << "An overflow occurred! ErrorCode = "
  22.              << ErrorCode << "\n";
  23.     }
  24. }
  25.