Skip to content

Some exceptions cannot be caught by a try/catch block or global exception handler #69585

Closed
@pweerd

Description

@pweerd

Describe the bug

Following code is causing an Exception that cannot be caught:

      try {
         char* p = (char*)0x100000000L;
         *p = ' ';
      } catch (Exception err) {
         MessageBox.Show (null, err.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
      }

If this code is executed, the application silently terminates.

This is a major problem, since I'mwriting a text editor, where:

  • I cannot offer my users a way to quickly safe their work
  • I cannot inform my user what happened
  • I cannot log the error, which makes it much harder to diagnose. Especially when the user is remote.
    There is only a message in the eventlog. And there might be a WER report. Both give not enough information to do a post mortem a diagnose.

To Reproduce

Please have a look at https://github.com/pweerd/ExceptionBug.
You can press the 2nd button, which should be caught by the unhandled exception handler, or press the 3rd button, which should be caught be its own try/catch block.

Exceptions (if any)

The example causes a System.AccessViolationException

Further technical details

My dotnet runtime info:

.NET SDK (reflecting any global.json):
 Version:   6.0.200
 Commit:    4c30de7899

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19044
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\6.0.200\

Host (useful for support):
  Version: 6.0.2
  Commit:  839cdfb0ec

.NET SDKs installed:
  6.0.200 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 5.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 5.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 5.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download```

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions