Is there a setting that is preventing the unhandled exception dialog from displaying in apps that I compile?

前端 未结 2 1473
广开言路
广开言路 2020-12-05 21:35

I\'m not sure if this is the right place to ask but I shall anyway.

I have 2 .NET applications; one that was compiled by myself, the other not. Both use .NET Framewo

2条回答
  •  無奈伤痛
    2020-12-05 22:24

    The solution presented by Hans Passant will terminate the application. This also means that remaining finally blocks are not executed any more.

    You can also use PInvoke to change the behavior by calling the SetErrorMode() method.

    public enum ErrorModes : uint
    {
        SYSTEM_DEFAULT = 0x0,
        SEM_FAILCRITICALERRORS = 0x0001,
        SEM_NOALIGNMENTFAULTEXCEPT = 0x0004,
        SEM_NOGPFAULTERRORBOX = 0x0002,
        SEM_NOOPENFILEERRORBOX = 0x8000,
        SEM_NONE = SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX
    }
    
    [DllImport("kernel32.dll")]
    static extern ErrorModes SetErrorMode(ErrorModes uMode);
    

    and then call

    SetErrorMode(ErrorModes.SEM_NONE);
    

    Doing so will give the finally blocks the chance to run.

提交回复
热议问题