Exception Handling, How? Try/Catch throw...
I have a menu that a user must enter a number to navigate. When the user enters anything else but a integer the program goes into a infinte loop. So I am trying to do some exception handling work. Hear is what I have....
Code:
void Controller::CommandControl(int input)
{
try{
if (input == 1)
{
menu.Info(); //Displays info about program
}
else if (input == 2)
{
CdInfoMenu();
}
else if (input == 3)
{
cout << "Goodbye" << endl; //End Program
}
else if (input != 1,2,3)
{
throw input;
}
else
{
cout << input << ": is not a valid command" << endl;
}
}
catch (char input)
{
cout << input << ": is not a vaild command" << endl;
}
}
Is it possible to through a data type. I want to be able to through any input that is not an int and catch in a catch block. How do you through a data type i.e char or string.