I have a custom exception which is
class RenterLimitException : public std::exception
{
public:
const char* what();
};
What is the proper way to override what()? For now, I created this custom in a header file and want to override what() in my cpp file. My function is defined as following:
const char* RenterLimitException::what(){
return "No available copies.";
}
However, when I use my try/catch block, it doesn't print the message that I gave to my function what(), instead, it prints std::exception
My try/catch block is this:
try{
if (something){
throw RenterLimitException();}
}
catch(std::exception& myCustomException){
std::cout << myCustomException.what() << std::endl;
}
Is it because my try/catch block or it is my what()
function?
Thanks in advance