I have a child of std::exception defined as:
struct image_load_failed : public std::exception
{
image_load_failed(std::string const s) : message(s) {}
virtual ~image_load_failed() throw() {}
const char* what() const throw()
{
return "image load failed";//message.c_str();
}
std::string const message;
};
(I would normally have what() return message.c_str(), but I've done it like this for debugging reasons).
It's thrown here:
throw image_load_failed(IMG_GetError());
and an atempt to catch it:
try
{
circle.loadImage("circle.bmp", Color(255,255,255));
}
catch(Surface::image_load_failed const& e)
{
std::cout << e.what() << std::endl;
throw e;
}
catch(std::exception const& e)
{
std::cout << e.what() << std::endl;
throw e;
}
this section of the code prints "std::exception". the exception that is then still being thrown causes the program to exit with:
terminate called after throwing an instance of 'std::exception'
what(): std::exception
adding throw(Surface::image_load_failed)
to the functions doesn't help. Anyone know why my classes are being interpreted as std::exceptions, and not the child classes I've created? (or more importantly, why the message is being lost)