home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Using Visual C++ 4 (Special Edition)
/
Using_Visual_C_4_Special_Edition_QUE_1996.iso
/
ch13
/
ellipsis.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1995-09-18
|
776b
|
36 lines
// 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";
}
}