處理未捕獲的異常,放在program類的Main函數下
1.UnhandledException
作用:接收未捕獲到的異常
例:
static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Console.WriteLine(e.ExceptionObject.ToString());
}
2.ThreadException
作用:winform接收UI線程的異常
static void Main()
{Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException)
Application.ThreadException += new ThreadExceptionEventHandler(UIThreadException);
}
private static void UIThreadException(object sender, ThreadExceptionEventArgs t)
{
}
參考:https://blog.csdn.net/lrh_079/article/details/7265486
