Original Post
I made a small class for exceptions in my program, but when I try to show the error with a MessageBox, the text just consists of like 50 Ý's. The text is just printed to the file so I could see if the string was right and it was.Btw, if I have overloaded a function, __FUNCTION__ just give the name so I don't know which of the functions who threw the exception. Ofcourse I could check the line number, but is the a way to get more that the name with some other macro? [Edited by - Eriond on November 29, 2004 12:32:58 PM]
class DXError
{
public:
DXError(const std::string& errorMessage, const std::string& fileName,
const std::string& function, int line)
: mErrorMessage(errorMessage), mFileName(fileName), mFunction(function),
mLine(line) {}
const char* ToString() const
{
std::string error;
error += "In file: " + mFileName + "\r\n";
error += "In function: " + mFunction + "\r\n";
error += "On line: " + boost::lexical_cast<std::string>(mLine) + "\r\n";
error += "\r\n" + mErrorMessage;
std::ofstream file("output.txt");
file << error;
return error.c_str();
}
private:
std::string mErrorMessage;
std::string mFileName;
std::string mFunction;
int mLine;
};
#define DX_ERROR(errorMessage) DXError(errorMessage, __FILE__, __FUNCTION__, __LINE__)
// later, catching the exception
catch(const DXError& e)
{
MessageBox(0, e.ToString(), "Error", 0);
return 0;
}