I have an exception class as follows:
class FileNotFoundException : public std::exception
{
public:
FileNotFoundException(const char* message) : errorMessage(message){ }
const char* what() const throw() override
{
return this->errorMessage;
}
private:
const char* errorMessage;
};
And I throw
this exception like this:
std::string message = "Message";
throw ::FileNotFoundException(message.c_str());
But when I try to handle it using:
try
{
// the code that throws
}
catch(::FileNotFoundException& ex)
{
std::string message = ex.what();
}
The string
is empty.
If anyone can help, I would gladly appreciate it.