在主入口复写下列方法
static void Main()
{
Application.ThreadException += Application_ThreadException;
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (new LangleyHR.LogonForm().ShowDialog() == DialogResult.OK)
{
Application.Run(new LangleyHR.Main());
}
private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs ex)
{
SaveErrorLogAndShowMessage(ex.Exception);
}
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
SaveErrorLogAndShowMessage(e.ExceptionObject as Exception);
}
}