home *** CD-ROM | disk | FTP | other *** search
- // 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";
- }
- }
-