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窗体线程异常,应用程序将退出!");
                }
            }
        }
  • 相关阅读:
    tensorflow2.0——手写数据集预测(多元逻辑回归)
    tensorflow2.0——鸢尾花数据集的一元分类
    tensorflow2.0——实现波士顿房价数据集的分类问题
    tensorflow2.0——代码实现一元逻辑回归
    tensorflow2.0——交叉熵损失函数
    tensorflow2.0——波士顿房价数据预测(3)
    子序列计数
    HDU 5687 Problem C
    linux中巧用ctrl-z后台运行程序
    Failed to set MokListRT: Invalid Parameter Something as gone seriously wrong: import_mok_state() failed: Invalid Parameter
  • 原文地址:https://www.cnblogs.com/zhangpengshou/p/1982287.html
Copyright © 2011-2022 走看看