Ejemplo n.º 1
0
        static void Main()
        {
            try
            {
                //设置应用的异常处理方式:异常捕获
                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
                //设置出现未处理异常的委托
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);


                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                frm = new Form1();
                Application.Run(frm);
            }catch (Exception ex)
            {
                string str = GetExceptionMsg(ex, string.Empty);
                MessageBox.Show(str, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                FileOperation.WriteLog(DateTime.Now.ToString() + "\r\n" + str);
                if (null != frm && null != frm.MyParamSet)
                {
                    SysParam.SaveAllInfor();
                }
            }
        }
Ejemplo n.º 2
0
        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            string str = GetExceptionMsg(e.ExceptionObject as Exception, e.ToString());

            MessageBox.Show(str, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            FileOperation.WriteLog(DateTime.Now.ToString() + "\r\n" + str);
            //查看若发现异常是在设置软体上出现的,此时是需要我们做数据保存
            if (null != frm.MyParamSet)
            {
                SysParam.SaveAllInfor();
            }
        }