Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# c UnhandledExceptionEventHandler不使用抛出新异常_C#_Exception_Exception Handling_Unhandled Exception - Fatal编程技术网

C# c UnhandledExceptionEventHandler不使用抛出新异常

C# c UnhandledExceptionEventHandler不使用抛出新异常,c#,exception,exception-handling,unhandled-exception,C#,Exception,Exception Handling,Unhandled Exception,因此,我在应用程序中内置了此异常处理程序,并且在使用时: throw new Exception("Message here"); 什么都没有发生,出于某种原因,它没有运行我的处理函数,有人知道为什么会发生这种情况吗?如果有,我能做些什么来纠正这种情况?理想情况下,我希望将所有异常路由到此函数 static class Program { private static void ExceptionHandler(object sender, UnhandledExceptionEven

因此,我在应用程序中内置了此异常处理程序,并且在使用时:

throw new Exception("Message here");
什么都没有发生,出于某种原因,它没有运行我的处理函数,有人知道为什么会发生这种情况吗?如果有,我能做些什么来纠正这种情况?理想情况下,我希望将所有异常路由到此函数

static class Program
{
    private static void ExceptionHandler(object sender, UnhandledExceptionEventArgs e)
    {
        if (e.ExceptionObject != null)
        {
            LoggerUtility.SendErrorEmail("[ERROR] - " + e.ExceptionObject.ToString());
            Application.Exit();
        }
    }

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Program.ExceptionHandler);
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }
}

这是因为WinForms在它的事件循环中捕获它。CodeInChaos,我也注意到了同样的事情,有没有办法全局捕获/重定向所有异常到一个特定的函数?这可能是重复的,因为WinForms在它的事件循环中捕获它。CodeInChaos,我也注意到了同样的事情,是否有一种方法可以全局捕获/重定向所有异常到特定函数?可能重复