troubleshooting Question

Input exceptions

Avatar of gil151
gil151 asked on
5 Comments2 Solutions249 ViewsLast Modified:
This program is just being used to test exceptions..It should throw exceptions until the value falls within the given range (here it is between 1 and 11)..  Doesnt have any real functionality, other than that..    It catches and handles the exception the first time through (using an input value of 11, which is "out of range" for this situation.. anyway if i input 12 the second time subRange is called (out of the catch statement), i get an error message "unhandled exception: int @ some memory address", instead of the generic "E" being thrown and being caught again in main..  i have a suspicion that it has something to do with the stack..  if anyone could explain the "why" behind this, i would appreciate it..

#include <iostream>

using namespace std;

class subRange

      subRange(int, int);
      int getValue( );

      int lower;
      int upper;


subRange::subRange(int low, int high)
      lower = low;
      upper = high;

int subRange::getValue()
                  int v;
                  int E = 1;
                  cout << "Enter value [ " << lower << ", " << upper << " ]: ";
                  cin >> v;
                  if(v < lower || v > upper)
                        throw E;  //unhandled error here after second call..
                  return v;

void main()
      subRange x(1, 10);
                catch(int )
            cout << "\nValue out of Range! \n";
            cout << x.getValue() << endl;

thanks... scf
Craig Wardman
Software Developer & Solution Architect

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros