Question: Part 1 : Define a new exception class named BadVarException that must inherit from the C + + runtime _ error class. This class will

Part 1:
Define a new exception class named BadVarException that must inherit
from the C++ runtime_error class. This class will capture the error case for a degree about the year and the name.
Part 2:
Rewrite the class named VariableInt in the previous exercise to generate a "BadVarException"
whenever the caller tries to create the VariableInt object with the following info:
- invalid variable name: empty or all blanks
- integer value is negative
Part 3:
Write a function named createVariableObject that will accept the variable name and the value
and it will create a VariableInt object dynamically.
If there is an exception, it will check to see if that is a bad integer value, then it will create a simple Variable object.
If the name is bad, it will return nullptr to the caller.
This function must handle all error cases for invalid name such as empty or blanks or invalid value (negative).
This function must use handle errors using try-catch the exception.
This function will return the pointer of the newly created VariableInt or Variable object or nullptr depending on the error it receives.
Note: there is no cin and cout in this function. All input and output must be done in the testing function.
Part 4:
The main() function to test createVariableObject:
Create at least 4 objects with different error cases. You can make up your own data. You do not need to get input from the user.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!