I am glad to answer you question. Once I met this problem. I suggest you can use dbghelp.dll.
You can search something about dbghelp.dll. It is very useful.
Here some examples:
First, you can write a function to handle the exception.
std::ostream& operator << ( std::ostream& os, const EXCEPTION_RECORD& red )
{
// Write your error handlding code here!!!
}
Second, create a exception filter.
You can also create a dump file here.
LONG __stdcall MyUnhandledExceptionFilter(PEXCEPTION_POINTERS pExceptionInfo)
{
std::cerr << " Unknown Error: " << (*pExceptionInfo->ExceptionRecord ) << std::endl;
exit( pExceptionInfo->ExceptionRecord->ExceptionCode );
return EXCEPTION_EXECUTE_HANDLER;
}
Then, call the function SetUnhandledExceptionFilter to set the exception filter. You must call this function before exception happens.
SetUnhandledExceptionFilter(MyUnhandledExceptionFilter);
Sometimes, you can use __try and __catch.
For example:
__try
{
// Which code may cause the exception, put them here!!!
} __except( EXCEPTION_EXECUTE_HANDLER )
{
// Handle exception or write you log file here. I think it's a good idea.
}
It's all. Nice day, man.