2

Our UWP app is mainly in C# but has a native DLL. When native code crashes CoreApplication.UnhandledErrorDetected is not fired (we have a C# handler for it). We have tried calling SetUnhandledExceptionFilter in the DLL, but our handler is not invoked.

BTW, CRT handlers do work (e.g. _set_invalid_parameter_handler).

In https://social.msdn.microsoft.com/Forums/windowsapps/en-US/9cddf0bc-8277-4534-b2c5-a96b9012e569/uwpc-is-it-possible-to-capture-unhandled-exceptions?forum=wpdevelop was a recommendation to use CoreApplicationExceptionHandler::OnUnhandledException.

I have tried embedding CoreApplicationExceptionHandler::OnUnhandledException in the native DLL and it has not helped at all.

  1. If the capturing is set in C# (first) the native handler is not invoked. It is invoked only if it is the first set (although in my test the handler propagates the exception).
  2. Native crashes in non WinRT code are not caught by the handler.

So how can native exceptions be captured???

A demo solution showing the problem is available here: https://drive.google.com/file/d/1-6r-XrOe6cRhZduRNA2HnhLm7eKQlGFU/view?usp=sharing

Thanks

Yakir Levi
  • 51
  • 2
  • When I set the option **Debugger type** of **Application process** (**Properties> Debug**) as **Mixed(Managed and Native)** in UWP project, I found the `code *pi = 5;` will trigger a breakpoint(write access violation) though the following `__try{}__except{}` try to catch the exception, and the code in `__except{}` will be executed after clicking Continue option. ``` int* pi = nullptr; __try{ *pi = 5; } __except(EXCEPTION_EXECUTE_HANDLER) { if (pi == nullptr) pi =new int[10]; } ``` – YanGu Jan 14 '21 at 07:33
  • When I set the option **Debugger type** of **Application process**(Properties> Debug) as `Managed Only` in UWP project, the same code won’t trigger a breakpoint and execute the code within __except{}. Therefore, the exception in dll is catched, but the breakpoint always occurs. – YanGu Jan 14 '21 at 07:33
  • Have you found any way to catch (track, record) native crash in UWP app ? I am in need of similar solution . Thanks. @Yakir Levi – Noorul Jul 21 '22 at 10:12

0 Answers0