SetUnhandledExceptionFilter not always called under Windows 10

SiMoStro 1 Reputation point
2021-11-24T11:24:11.033+00:00

We've a mixed application C/C++/.NET which is in the wild for about 15 years now and we use the aforementioned API syscall to install a handler from which, in case of crash, we produce a minidump (MiniDumpWriteDump).

Everything has worked pretty well for years but we noticed a relevant decrease in the reliability of this portion of code first when some of our clients switched to Windows 8.1 and then when (nearly) all switched to Windows 10. It's true that in the meantime other things have changed: the .NET version, we've moved from WinForms to WPF... but a crash should be still a crash and we have to recognize that in many, many case when our clients notifies us an application crash a dump is NOT created (but sometimes is!).

We've also suggested to enable Windows Error Reporting but this didn't help very much, so I was wondering if under Windows 10 this part of error handling and minidump creation had changed so much to make it worth it to use some new alternatives.
Thanks in advance,

Simone

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
11,197 questions
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,523 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. EckiS 831 Reputation points
    2021-11-24T17:43:42.1+00:00

    in some error cases the handler is not called, see the comments on:
    why-setunhandledexceptionfilter-cannot-capture-some-exception-but-addvectoredexc

    I would simple set the registry keys (f.e. in your setup) to let WER write the dump files for you, and remove the unhandled exception filter:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\YourProcessName.exe]
    "DumpType"=dword:00000001

    you can control the writing of the dump file as explained in:
    collecting-user-mode-dumps

    1 person found this answer helpful.
    0 comments No comments

  2. Limitless Technology 39,511 Reputation points
    2021-11-29T09:34:19.79+00:00

    Hi there,

    The safest way to handle this problem is to avoid the unhandled exception hook entirely and simply use __try/__except around all of your DLL entry points instead -- a bit of a sledgehammer approach, but a sure way to scope the handling to your own code. Do not use try/catch, as it will not catch non-C++ exceptions in VC8 and up.

    Issuing SetUnhandledExceptionFilter replaces the existing top-level exception filter for all existing and all future threads in the calling process.

    The exception handler specified by lpTopLevelExceptionFilter is executed in the context of the thread that caused the fault. This can affect the exception handler's ability to recover from certain exceptions, such as an invalid stack.

    You can get a look into this forum for more troubleshooting steps https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/0ac370e2-14f0-45d3-84c1-1d001abaf978/setunhandledexceptionfilter-problem?forum=windowssdk


    --If the reply is helpful, please Upvote and Accept it as an answer--

    0 comments No comments

  3. SiMoStro 1 Reputation point
    2021-12-06T09:07:41.13+00:00

    Hi all,

    in these cases we quite regularly suggest out client to disable our internal minidump service (there's a switch for this) and to try to fallback to WER but to be honest also WER pretty often fails to produce the dump.

    Anyway thanks for your feedback, I'll review how we init this and see if I can get something better.

    Simo

    0 comments No comments