zoukankan      html  css  js  c++  java
  • Catch Application Exceptions in a Windows Forms Application

    You need to handle the System.Windows.Forms.Application.ThreadException event for Windows Forms. This article really helped me: http://bytes.com/forum/thread236199.html.

    Application.ThreadException += new ThreadExceptionEventHandler(MyCommonExceptionHandlingMethod)
    
    private static void MyCommonExceptionHandlingMethod(object sender, ThreadExceptionEventArgs t)
    {
        //Exception handling...
    }
    
    AppDomain.UnhandledException and Application.ThreadException.

    http://msdn.microsoft.com/en-us/library/system.appdomain.unhandledexception.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2

    using System;
    using System.Security.Permissions;
    
    public class Example 
    {
       [SecurityPermission(SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlAppDomain)]
       public static void Main()
       {
          AppDomain currentDomain = AppDomain.CurrentDomain;
          currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);
    
          try {
             throw new Exception("1");
          } catch (Exception e) {
             Console.WriteLine("Catch clause caught : {0} 
    ", e.Message);
          }
    
          throw new Exception("2");
       }
    
       static void MyHandler(object sender, UnhandledExceptionEventArgs args) 
       {
          Exception e = (Exception) args.ExceptionObject;
          Console.WriteLine("MyHandler caught : " + e.Message);
          Console.WriteLine("Runtime terminating: {0}", args.IsTerminating);
       }
    }
  • 相关阅读:
    git
    centos7安装python3和ipython
    centos7 安装mysql5.7
    ceph-文件存储
    ceph-对象存储
    ceph-块存储客户端
    ceph-简介及安装(luminous)版
    centos7 kvm安装使用
    webpack多页面应用打包问题-新增页面打包JS影响旧有JS资源
    webpack4.0 babel配置遇到的问题
  • 原文地址:https://www.cnblogs.com/zyip/p/3694683.html
Copyright © 2011-2022 走看看