zoukankan      html  css  js  c++  java
  • .net winform全局异常处理

    static class Program     
    {     
        /// <summary>     
        /// 应用程序的主入口点。     
        /// </summary>     
        [STAThread]     
        static void Main()     
        {     
            // Add the event handler for handling UI thread exceptions to the event.     
            Application.ThreadException += new ThreadExceptionEventHandler(Form1_UIThreadException);     
        
            // Set the unhandled exception mode to force all Windows Forms errors to go through     
            // our handler.     
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);     
        
            // Add the event handler for handling non-UI thread exceptions to the event.      
            AppDomain.CurrentDomain.UnhandledException +=     
                new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);     
        
            //------------------------     
            Application.EnableVisualStyles();     
            Application.SetCompatibleTextRenderingDefault(false);     
            Application.Run(new Form1());     
        }     
        
        // Handle the UI exceptions by showing a dialog box, and asking the user whether     
        // or not they wish to abort execution.     
        private static void Form1_UIThreadException(object sender, ThreadExceptionEventArgs t)     
        {     
            MessageBox.Show("1:"+t.Exception.ToString());     
        }     
        
        // Handle the UI exceptions by showing a dialog box, and asking the user whether     
        // or not they wish to abort execution.     
        // NOTE: This exception cannot be kept from terminating the application - it can only      
        // log the event, and inform the user about it.      
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)     
        {     
            Exception ex = (Exception)e.ExceptionObject;     
            string errorMsg = "An application error occurred. Please contact the adminstrator " +     
                "with the following information:\n\n";     
            errorMsg += ex.Message + "\n\nStack Trace:\n" + ex.StackTrace;     
        
            MessageBox.Show("2:" + errorMsg);     
        }     
        
    }    
    
  • 相关阅读:
    JavaScript 学习笔记 事件二
    auto_ptr
    POJ2299 UltraQuickSort(逆序对个数)
    2016年11月2日22:28:14
    将sql server中的数据倒入Excel(c#)
    线段树成段更新裸题POJ3468
    线段树成断更新裸题hdu1698 Just a Hook
    POJ2828 思维难度较好的一道线段树
    < 弱牛刷贪心给JerryDung&qiuwei大神Orz>最大乘积
    NOIP 2008 传纸条题解[双线程DP]
  • 原文地址:https://www.cnblogs.com/cwfsoft/p/2039291.html
Copyright © 2011-2022 走看看