国产探花免费观看_亚洲丰满少妇自慰呻吟_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);    }}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 拉萨市| 安阳县| 平定县| 乐业县| 邢台市| 商洛市| 木里| 临潭县| 霍山县| 祁连县| 贵定县| 凉城县| 苏尼特左旗| 呼图壁县| 社会| 奉贤区| 靖州| 定陶县| 成武县| 格尔木市| 巨鹿县| 舒城县| 大理市| 霍州市| 通城县| 琼结县| 手机| 镇康县| 香港 | 台北县| 阿拉尔市| 政和县| 南平市| 通化县| 山西省| 西华县| 玉溪市| 香河县| 赣榆县| 胶州市| 韶关市|