Question
Add an exception handler (try/catch/throw) to the class that throws an error message (e.g. value out of range) in the getValue function that is caught
Add an exception handler (try/catch/throw) to the class that throws an error message (e.g. value out of range) in the getValue function that is caught and handled in the main program. Implement two version of the program. In version 1, throw the error in getValue, catch the error in the main, display an error message in the main, and then allow the program to PROBLEM NO.6
PROBLEM NO.7
PROBLEM NO.8
terminate. In the second version, perform the same basic actions (throw and catch) but keep re-invoking the getValue function from the main program until the user enters a valid value. // Starter Code class subRange { public: subRange( int, int ); int getValue( ); private: int lower, upper; }; subRange::subRange( int low, int high ) { lower = low; upper = high; } int subRange::getValue() { int v; cout << "Enter value [ " << lower << ", " << upper << " ]: "; cin >> v; return v; } void main() { subRange x(1,10); cout << x.getValue( ) << endl; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started