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,我也注意到了同样的事情,是否有一种方法可以全局捕获/重定向所有异常到特定函数?可能重复