home *** CD-ROM | disk | FTP | other *** search
- // Get needed include files
- #include <limits.h>
- #include <iostream.h>
- #include <eh.h>
-
- unsigned short Add(unsigned short addend1, unsigned short addend2)
- {
- unsigned long sum = addend1 + addend2;
- if (sum > USHRT_MAX)
- throw 1;
- return (unsigned short) sum;
- }
-
- unsigned short Divide(unsigned short dividend, unsigned short divisor)
- {
- if (divisor == 0)
- throw "Divide by zero";
- return (dividend / divisor);
- }
-
- void main()
- {
- try {
- unsigned short Result = Add(12345, 12345);
- cout << "The first answer is " << Result << "\n";
- Result = Divide(55, 0);
- cout << "The second answer is " << Result << "\n";
- }
- catch (int) {
- cout << "An addition overflow occurred!\n";
- }
- catch (...) {
- cout << "Something else bad happened.\n";
- }
- }
-