国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

C# winform 捕獲全局異常

2019-11-08 03:09:58
字體:
來源:轉載
供稿:網友

static class PRogram{    /// <summary>    /// 應用程序的主入口點。    /// </summary>    [STAThread]    static void Main()    {        try        {            //處理未捕獲的異常            application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);            //處理UI線程異常            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);            //處理非UI線程異常            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            #region 應用程序的主入口點

            Application.EnableVisualStyles();            Application.SetCompatibleTextRenderingDefault(false);            Application.Run(new Main());

            #endregion

        }        catch (Exception ex)        {            string str = "";            string strDateInfo = "出現應用程序未處理的異常:" + DateTime.Now.ToString() + "/r/n";

            if (ex != null)            {                str = string.Format(strDateInfo + "異常類型:{0}/r/n異常消息:{1}/r/n異常信息:{2}/r/n",                ex.GetType().Name, ex.Message, ex.StackTrace);            }            else            {                str = string.Format("應用程序線程錯誤:{0}", ex);            }

            //MessageBox.Show(str, "系統錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);            LogManager.WriteLog(str);         }

    }

    static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)    {        string str = "";        string strDateInfo = "出現應用程序未處理的異常:" + DateTime.Now.ToString() + "/r/n";        Exception error = e.Exception as Exception;        if (error != null)        {            str = string.Format(strDateInfo + "異常類型:{0}/r/n異常消息:{1}/r/n異常信息:{2}/r/n",            error.GetType().Name, error.Message, error.StackTrace);        }        else        {            str = string.Format("應用程序線程錯誤:{0}", e);        }

        //MessageBox.Show(str, "系統錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);        LogManager.WriteLog(str);    }

    static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)    {        string str = "";        Exception error = e.ExceptionObject as Exception;        string strDateInfo = "出現應用程序未處理的異常:" + DateTime.Now.ToString() + "/r/n";        if (error != null)        {            str = string.Format(strDateInfo + "Application UnhandledException:{0};/n/r堆棧信息:{1}", error.Message, error.StackTrace);        }        else        {            str = string.Format("Application UnhandledError:{0}", e);        }

        //MessageBox.Show(str, "系統錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);        LogManager.WriteLog(str);    }}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 江口县| 陆川县| 武鸣县| 囊谦县| 顺平县| 金川县| 阳春市| 荣昌县| 卓资县| 根河市| 诸暨市| 兴安县| 武冈市| 南充市| 丰原市| 丰宁| 宁海县| 玉溪市| 武乡县| 内乡县| 昌邑市| 石楼县| 石景山区| 杭锦后旗| 屏山县| 平原县| 罗江县| SHOW| 叙永县| 平凉市| 诏安县| 壤塘县| 仪陇县| 浏阳市| 廉江市| 宁阳县| 柏乡县| 庆安县| 库尔勒市| 武城县| 道孚县|