0

I'm getting a 0xC0000005 exception (0xC0000005: Access violation reading location 0x00000004.) when a COM function doesn't return. This is a very edge case, however it still needs to be caught in the C++ code that is calling it. For some reason, this exception is not being caught using a 'catch all' and I can't figure out why.

Here's the problematic code:

try
{
    p_rsFuncResult = (LPCTSTR)myPtr->myFunction(p_szFuncInput);
}
catch (std::exception& e)
{
    LOG_FATAL << "Uncaught exception thrown in myFunction: " << e.what();
    p_rsFuncResult = "";
}

I've also tried catching using just '...', but this code still isn't being hit. It's worth noting as well that everything works as expected when the COM function returns as expected.

Can anyone provide any insight into this?

tj_ush
  • 69
  • 2
  • 10
  • 1
    I know no implementation that throws exception on invalid pointer dereferences (they are UB as far as the language is concerned). But MS has a flag for it, see the dupe. – Rakete1111 Feb 25 '18 at 18:59
  • 1
    @Rakete1111 Windows can transform access violations into exceptions, [see here](https://msdn.microsoft.com/en-us/library/1deeycx5.aspx) – M.M Feb 25 '18 at 20:36
  • @M.M Yes. I don't believe I said otherwise though :) – Rakete1111 Feb 25 '18 at 20:38

0 Answers0