static class Program {
/// <summary>
///
应用程序的主入口点。
///
</summary>
[STAThread]
static void Main()
{
Application.ThreadException += new
System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
AppDomain.CurrentDomain.UnhandledException
+= new
UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new
Form1());
}
static void
Application_ThreadException(object sender,
System.Threading.ThreadExceptionEventArgs e) {
Exception ex
=
e.Exception;
MessageBox.Show(ex.Message);
}
static
void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs
e) {
Exception ex =
(Exception)e.ExceptionObject;
MessageBox.Show(ex.Message);
}
}
可以结合网上记录错误日志的通用方法推荐:Log4Net