窗体中事件,方法比较多,如果能提供一个捕获异常事件的方法的话,类似于B/S中的application_error事件什么的。这样我就不必在每个方法,事件里都要去写try{}....catch(){}了。有这样的一个事件么,如果没有的话,有其他的解决办法么? 谢谢!

解决方案 »

  1.   

    Program.cs
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
            }        static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
            {
                throw new NotImplementedException();
            }
      

  2.   

    非常感谢,不过你上面的代码是捕捉线程异常的!
                
    Application.SetCompatibleTextRenderingDefault(false);
                Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
                Application.EnableVisualStyles();
                    Application.Run(new Frm_Login());
                 
                
            }
            
            
            static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
            {
                
            }        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
            {
                
            }