全局未处理异常捕获

控制台、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);
        }

 

posted on 2014-03-20 23:01  harrell  阅读(180)  评论(0)    收藏  举报