One problem of your exception class:
Code:
#include "cexception.h"
void f ( )
{
char msg[100];
strcpy(msg, "Oh no, not again.");
throw cException(42, msg);
}
int main ( )
{
try
{
f ( );
}
catch ( cException& exception )
{
// I need these temp vars
int i = 0x4F4F4F4F, j = 0x4F4F4F4F, k = 0x4F4F4F4F, l = 0x4F4F4F4F, m = 0x4F4F4F4F;
cerr << exception.ErrorMessage(); // likely not what you expect
// might even crash
}
return 0;
}
The reason is that cException only stores a pointer, which might not point to permanent memory which could get overwritten (in my example I expect it to get overwritten by my temp vars).
cException should store the data internally, either by allocating in the constructor and deallocating in the destructor or using a std::string.