zoukankan      html  css  js  c++  java
  • 窗体程序捕捉异常的通用简便方法不用到处添加try-catch

    static class Program {
      /// <summary>
      /// 应用程序的主入口点。
      /// </summary>
      [STAThread]
      static void Main() {
       Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
       AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
       Application.EnableVisualStyles();
       Application.SetCompatibleTextRenderingDefault(false);
       Application.Run(new Form1());
      }
      static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) {
       Exception ex = e.Exception;
       MessageBox.Show(ex.Message);
      }
      static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) {
       Exception ex = (Exception)e.ExceptionObject;
       MessageBox.Show(ex.Message);
      
      }
     }

    可以结合网上记录错误日志的通用方法推荐:Log4Net

    下载地址http://logging.apache.org/log4net/download_log4net.cgi

  • 相关阅读:
    leetcode59
    leetcode95
    leetcode96
    leetcode787
    leetcode150
    leetcode165
    leetcode739
    快速搭建:Djangorest-framework的restful项目
    编写部署用到的部分shell脚本收集
    pandas:dataframe删除某些不为non的行
  • 原文地址:https://www.cnblogs.com/lczblog/p/3518487.html
Copyright © 2011-2022 走看看