title: Catch the "Access violation reading location 0x00000000" exception
body: <p>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. </p>
  
  <p>1, </p>
  
  <pre><code>try
      {
      sts = resFilter-&gt;initialize(m_JPEG2000File); // it throws that exception
      }
      catch (...){
          printf("Gotcha0...");
          int a = 34;
      }
  </code></pre>
  
  <p>2, 3 and 4 </p>
  
  <pre><code>LONG WINAPI CrashHandler1(EXCEPTION_POINTERS * a/*ExceptionInfo*/)
  {  std::cout &lt;&lt; "Gotcha1!" &lt;&lt; std::endl;
  return 0;
  }
  
  void CrashHandler2()
  {    std::cout &lt;&lt; "Gotcha2!" &lt;&lt; std::endl;}
  
  void CrashHandler3()
  {    std::cout &lt;&lt; "Gotcha3!" &lt;&lt; std::endl;}
  
  // in Main()
  ::SetUnhandledExceptionFilter(CrashHandler1);
  std::set_terminate (CrashHandler2);
  std::set_unexpected( CrashHandler3 );
  
  Test(); // It would throw "Access violation reading location 0x00000000" exception 
  </code></pre>
  
  <p>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? </p>
  
  <p>Thanks in advance, </p>
  
  <p>Ben</p>
  
  <p>Edit: </p>
  
  <p>@Adriano Repetti mentioned __try and __except can catch this exception. </p>
  
  <p>Thanks for all you guys heads-up for not eating that exception! </p>
  
  <p>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. </p>