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());
        }

猜你喜欢

转载自www.cnblogs.com/gaara-zhang/p/10103864.html
今日推荐