home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Using Visual C++ 4 (Special Edition)
/
Using_Visual_C_4_Special_Edition_QUE_1996.iso
/
ch13
/
jump.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1995-09-18
|
576b
|
30 lines
// Get needed include files
#include <limits.h>
#include <iostream.h>
#include <setjmp.h>
jmp_buf jmp_info;
unsigned short Add(unsigned short addend1, unsigned short addend2)
{
unsigned long sum = addend1 + addend2;
if (sum > USHRT_MAX)
longjmp(jmp_info, -1);
return (unsigned short) sum;
}
void main()
{
int ErrorCode = setjmp(jmp_info);
if (ErrorCode == 0) {
unsigned short Result = Add(12345, 54321);
cout << "The answer is " << Result << "\n";
return;
}
// Error handling section
else {
cout << "Overflow error!\n";
}
}