zoukankan      html  css  js  c++  java
  • 公用类库(3) 异常处理类ExceptionHandlingUtil

      首先创建配置文件,代码如下:

    View Code
    <exceptionHandling>
            <exceptionPolicies>
                <add name="Default Policy">
                    <exceptionTypes>
                        <add name="All Exceptions" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                            postHandlingAction="NotifyRethrow">
                            <exceptionHandlers>
                                <add name="Logging Exception Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                                    logCategory="Exception" eventId="100" severity="Error" title="Enterprise Library Exception Handling"
                                    formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
                                    priority="0" />
                            </exceptionHandlers>
                        </add>
                    </exceptionTypes>
                </add>
            </exceptionPolicies>
        </exceptionHandling>

      两个公开方法,全部代码如下:

    namespace Tmac.Utilities
    {
        /// <summary>
        /// 异常处理操作类
        /// </summary>
        public class ExceptionHandlingUtil
        {
            //默认策略,与配置文件中定义的一致
            private const string defaultPolicy = "Default Policy";
    
            /// <summary>
            /// 记录异常日志
            /// </summary>
            /// <param name="ex"></param>
            /// <returns></returns>
            public static bool HandleException(Exception ex)
            {
                return HandleException(ex,defaultPolicy);
            }
    
            public static bool HandleException(Exception ex, string policy)
            {
                return ExceptionPolicy.HandleException(ex, policy);  
            }
        }
    }
  • 相关阅读:
    Pytest学习之 autouse=True,自动调用fixture功能
    Pytest学习之xfail使用
    Pytest学习之use fixtures
    python
    python
    python
    python
    python
    python
    python
  • 原文地址:https://www.cnblogs.com/mcgrady/p/2970109.html
Copyright © 2011-2022 走看看