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

  1. // Get needed include files
  2. #include <limits.h>
  3. #include <iostream.h>
  4.  
  5. unsigned short Add(unsigned short addend1, unsigned short addend2)
  6. {
  7.     unsigned long sum = addend1 + addend2;
  8.     if (sum > USHRT_MAX)
  9.         goto OverflowError; // Illegal _ can't leave Add()
  10.     return (unsigned short) sum;
  11. }
  12.  
  13. void main()
  14. {
  15.     unsigned short Result = Add(12345, 54321);
  16.     cout << "The answer is " << Result << "\n";
  17.     return;
  18.  
  19.     // Error handling section - but you'll never get here using 
  20.     // this program
  21. OverflowError:
  22.     cout << "Overflow error!\n";
  23.     return;
  24. }
  25.