I'm using a method from 3rd party dll and it throws "Access violation reading location 0x00000000" exception. I cannot dig in so I'm only wondering if there is anyway to catch it so not collapse the application. I tried the following 4 methods but none of them works.
1,
try
{
sts = resFilter->initialize(m_JPEG2000File); // it throws that exception
}
catch (...){
printf("Gotcha0...");
int a = 34;
}
2, 3 and 4
LONG WINAPI CrashHandler1(EXCEPTION_POINTERS * a/*ExceptionInfo*/)
{ std::cout << "Gotcha1!" << std::endl;
return 0;
}
void CrashHandler2()
{ std::cout << "Gotcha2!" << std::endl;}
void CrashHandler3()
{ std::cout << "Gotcha3!" << std::endl;}
// in Main()
::SetUnhandledExceptionFilter(CrashHandler1);
std::set_terminate (CrashHandler2);
std::set_unexpected( CrashHandler3 );
Test(); // It would throw "Access violation reading location 0x00000000" exception
If I debug it, exception would be thrown. If I run it in run time, "Gotcha1!" would be displayed in the console but the application would still collapse. Is there any way I can eat this exception?
Thanks in advance,
Ben
Edit:
@Adriano Repetti mentioned __try and __except can catch this exception.
Thanks for all you guys heads-up for not eating that exception!
I have an external C# executable calling this project. I want to catch this exception so I have chance to log the error and do not collapse the C# application. I would still terminate this very c++ process. I'm looping the data in C# which would start a new C++ process from scratch every time, so it would be a new C++ instance. So Adriano's approach works for me.