home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Using Visual C++ 4 (Special Edition)
/
Using_Visual_C_4_Special_Edition_QUE_1996.iso
/
ch13
/
nested.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1995-09-18
|
1KB
|
52 lines
// Get needed include files
#include <stdlib.h>
#include <iostream.h>
#include <eh.h>
// Constants
const int MIN_FLAG_VALUE = 0;
const int MAX_FLAG_VALUE = 10;
const int FLAG_OUT_OF_BOUNDS = 0xFF;
// Processing
void DoSomethingElse()
{
cout << "Inside DoSomethingElse.\n";
}
void DoSomethingUseful(int Flag)
{
cout << "Inside DoSomethingUseful.\n";
// Is our flag too big or too small?
if (Flag < MIN_FLAG_VALUE || Flag > MAX_FLAG_VALUE)
throw FLAG_OUT_OF_BOUNDS;
// Do some processing
try {
if (Flag == 0) {
cout << "The flag was set to zero.\n";
DoSomethingElse();
}
else
throw "Flag is non-zero.";
}
catch (char *ErrorString) {
cout << ErrorString << "\n";
}
}
void main(int argc, char *argv[ ])
{
// If no command-line arguments, set the flag to zero
int UseFlag = (argc == 1 ? 0 : atoi(argv[1]));
// Do some processing
try {
DoSomethingUseful(UseFlag);
}
catch (int ErrorCode) {
cout << "Caught an exception (" << ErrorCode << ")\n";
}
}