c# 捕获一般获取不到的异常

1.主函数入口加异常事件,代码例如:

/// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
        }

        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            MessageBox.Show(e.ExceptionObject.ToString());
        }

 

posted @ 2018-12-11 18:02  风影我爱罗  阅读(944)  评论(0)    收藏  举报