全局未处理异常捕获

控制台、WinForm程序可以用以下方法做全局捕获

AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            var error = (Exception)e.ExceptionObject;
            Console.WriteLine("MyHandler caught : " + error.Message);
            Console.Read();
            Environment.Exit(0);
        }
原文地址:https://www.cnblogs.com/haorui/p/3614862.html