Use std::runtime_error
, eg:
#include <stdexcept>
class myClass()
{
public:
myClass()
{
//Do work...check for errors
if(var < 0)
{
//Error
char buff[1024];
_snprintf_s(buff, SIZEOF(buff), "ERROR: The value of var=%d", var);
throw std::runtime_error(buff);
}
}
};
try
{
//Begin using class above
myClass mc;
}
catch (const std::runtime_error &e)
{
//Process unhandled exception
//e.what() will return the string message ...
}