Original Post
I just started to use try and catch blocks for my new program. I made a class called CException that holds a long and 3 std::string's (Error Msg, Line, Filename, Function Name). I have the code like this The compiler gives an error msg for THROW_STR(); "expected primary-expression before '(' token", I was going to say it gives an error msg for catch(CException e) too but I hit rebuild all again while I was writing this and it worked :-/. Also if I comment out the try / catch blocks and put before them it gives me these errors "[Linker error] undefined reference to it won't put that text in the log but the text from ProgCleanup(); gets put in :-/, any help would be really nice :D I RARed and uploaded my code to > http://www.dragonruins.com/MyCode.rar You need v2.9 or > to UnRAR it (WinRAR - http://www.rarlabs.com/ of course :) ) I'm using Dev-CPP v4.9.9.1 - http://www.bloodshed.net/ (Use's gcc as the compiler) to compile everything. And how do you get URL's to work? Thanks ;-)
try
{
// THROW_STR is a macro in CException.h along with THROW_NUM and THROW
THROW_STR("THIS IS A TEST :P");
}
catch(CException e)
{
// e.Format().c_str() wont work in the call to AddLog for some reason
// Format returns a std::string with everything in it ;)
string strError = e.Format();
// AddLog of course adds the text to the log
AddLog("\nException thrown!\n%s", strError.c_str());
}
ProgCleanup();
return g_iExitCode;
CException e("TEST", -1, __FILE__, __LINE__, __FUNCTION__);
AddLog("\nException thrown!\n%s", e.Format().c_str());
CException::CException(std::string, long, std::string, long, std::string)'" "[Linker error] undefined reference to CException::Format()'" "[Linker error] undefined reference to CException::~CException()'" "[Linker error] undefined reference to CException::~CException()'" yes it repeated that one twice and when I just use
try
{
throw "TEST";
}
catch(string s)
{
string strError = s;
AddLog("\nException thrown!\n%s", strError.c_str());
}
ProgCleanup();
return g_iExitCode;