Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Function Prototypes
- void Menu();
- void OverflowFunction();
- void SubscriptFunction();
- void MemoryFunction();
- // The purpose of this program is to test
- // different exceptions using classes that we have
- // created. We use 3 functions to create our environments
- // that we will need to throw our exception.
- // Program entry point
- int main()
- {
- Menu();
- return 0;
- }
- // This will be the core to our program, it will prompt the user
- // and it will also call our functions to test each exception.
- // This menu will give the user the chance to try again if they so desire
- // to.
- void Menu()
- {
- int userChoice;
- char userTryAgain;
- bool goAgain;
- cout << "Welcome to The Exception Handling Test Program\n"
- << "this program will test three different exceptions.\n"
- << "These exceptions have been created in a specialized\n"
- << "environment in order to prevent catastrophic results\n"
- << "we recommend that you do not try this at home." << endl;
- do
- {
- cout << "\nPlease select an Exception Handler to test." << endl;
- cout << "1) Overflow Exception\n"
- << "2) Subscript Exception\n"
- << "3) Memory Exception\n" << endl;
- cin >> userChoice;
- try
- {
- switch (userChoice)
- {
- case 1:
- cout << "\nInteger Overflow\n" << endl;
- OverflowFunction();
- break;
- case 2:
- cout << "\nSubscript Out-of-Bounds\n" << endl;
- SubscriptFunction();
- break;
- case 3:
- cout << "\nMemory Allocation Failure\n" << endl;
- MemoryFunction();
- break;
- }
- }
- catch (const OverflowException& exception)
- {
- cout << "\nException Thrown: " << exception.what();
- }
- catch (const SubscriptException& exception)
- {
- cout << "\nException Thrown: " << exception.what();
- }
- catch (const MemoryException& exception)
- {
- cout << "\nException Thrown: " << exception.what() << endl;
- }
- cout << "\nGo again? (y/n)" << endl;
- cin >> userTryAgain;
- if (userTryAgain == 'y')
- goAgain = true;
- else
- goAgain = false;
- } while (goAgain);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement