I'm just writing my errors as words.
Should I catch them as char* v
, char v
or const char* v
?
try{
int choice = 1
if(choice != 2)
throw choice;
}
catch(char* v){
if (v == choice)
cout << "Error: choice != 2."
}
I'm just writing my errors as words.
Should I catch them as char* v
, char v
or const char* v
?
try{
int choice = 1
if(choice != 2)
throw choice;
}
catch(char* v){
if (v == choice)
cout << "Error: choice != 2."
}
Try this instead:
try
{
int choice = 1;
if(choice != 2)
{
throw std::runtime_error("choice != 2");
}
}
catch(std::exception& e)
{
std::cout << "Error: " << e.what() << "\n";
}
std::exceptions are the preferred objects to be thrown and the error location knows best to provide a description of what is happening.