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窗体线程异常,应用程序将退出!");
                }
            }
        }
  • 相关阅读:
    Spring MyBatis多数据源分包
    ubuntu Ngin Install
    Ubuntu16.04开启root用户,并远程登录
    ubuntu16.04LTS更换阿里源
    修改DIV滚动条样式
    Spring-Boot配置文件数据源配置项
    Springboot 版本+ jdk 版本 + Maven 版本的对应关系
    CAS配置(3)之restful-api接入接口
    Java.Cas4.0客户端接入配置
    Java.HttpClient绕过Https证书解决方案二
  • 原文地址:https://www.cnblogs.com/zhangpengshou/p/1982287.html
Copyright © 2011-2022 走看看