I have a block of code that I put in place to check for errors after a function runs. But this block of code is itself causing problems.
ErrorType *error;
CreateObject(..., &error); // Function argument is ErrorType**
if (error) // nullptr if no error
{
log << "Error details here." << std::endl;
log.close();
return false; // Causes application to PROPERLY quit
}
The debugger gives me a "memory access violation, line 3" error quite frequently and half the time, without using a debugger, this code causes a CTD while other times it executes just fine (When running the debugger, I can just hit "Continue" a few times until the block executes as intended.) Do I need to specify something like if (error != nullptr)
to get it to work properly? Why is this error-checking block causing errors and how do I fix it?
Note that CreateObject()
is an external API function that does not throw any exceptions.