zoukankan      html  css  js  c++  java
  • UnhandledException

    static class Program
        {
            
    /// <summary>
            
    /// The main entry point for the application.
            
    /// </summary>
            [STAThread]
            
    static void Main()
            {
                
    //异常捕捉
                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                Application.ThreadException 
    += new ThreadExceptionEventHandler(UIThreadException);
                AppDomain.CurrentDomain.UnhandledException 
    += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
                
                
    //正常程序运行处
                Application.EnableVisualStyles();  Application.SetCompatibleTextRenderingDefault(false);  Application.Run(new AutoJudge());
            }
            
    /// <summary>
            
    /// 线程异常捕捉
            
    /// </summary>
            
    /// <param name="sender"></param>
            
    /// <param name="t"></param>
            private static void UIThreadException(object sender, ThreadExceptionEventArgs t)
            {
                
    try
                {
                    
    string errorMsg = "Windows窗体线程异常:";
                    MessageBox.Show(errorMsg 
    + t.Exception.Message + Environment.NewLine + t.Exception.StackTrace);
                }
                
    catch
                {
                    MessageBox.Show(
    "不可恢复的Windows窗体异常,应用程序将退出!");
                }
            }
            
    /// <summary>
            
    /// 非线程异常捕捉
            
    /// </summary>
            
    /// <param name="sender"></param>
            
    /// <param name="e"></param>
            private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
            {
                
    try
                {
                    Exception ex 
    = (Exception)e.ExceptionObject;
                    
    string errorMsg = "非Windows窗体线程异常:";
                    MessageBox.Show(errorMsg 
    + ex.Message + Environment.NewLine + ex.StackTrace);
                }
                
    catch
                {
                    MessageBox.Show(
    "不可恢复的非Windows窗体线程异常,应用程序将退出!");
                }
            }
        }
  • 相关阅读:
    细说进程、应用程序域与上下文之间的关系
    sql server2008添加登录账户配置权限 && 登录时18456错误
    Sql CLR
    设计模式学习篇(一)
    常用实用方法
    OOP 6大基本原则
    如何成为一个优秀的程序员
    家庭网络
    反射
    ADO.Net 事务操作
  • 原文地址:https://www.cnblogs.com/zhangpengshou/p/1982287.html
Copyright © 2011-2022 走看看