zoukankan      html  css  js  c++  java
  • Exception

    库:http://crashreporterdotnet.codeplex.com/documentation

    private
    void ThrowException<T>(string message, params object[] values) where T : Exception, new() { // NOTE Cannot provide arguments when creating an instance of a type parameter T. var exception = (T)Activator.CreateInstance(typeof(T), string.Format(message, values)); throw exception; }

    And you would simply use it like this:

    ThrowException<InvalidOperationException>("VehicleMovementBatch Id {0} was not located.", batchId); 
    ************

    Define custom exception class:
    [Serializable]
    public class CustomException : Exception
    {
        public CustomException()
            : base() { }
        
        public CustomException(string message)
            : base(message) { }
        
        public CustomException(string format, params object[] args)
            : base(string.Format(format, args)) { }
        
        public CustomException(string message, Exception innerException)
            : base(message, innerException) { }
        
        public CustomException(string format, Exception innerException, params object[] args)
            : base(string.Format(format, args), innerException) { }
        
        protected CustomException(SerializationInfo info, StreamingContext context)
            : base(info, context) { }
    }

    Example:
     
    1. Throw exception with out message
    throw new CustomException()
    2. Throw exception with simple message
    throw new CustomException(message)
    3. Throw exception with message format and parameters
    throw new CustomException("Exception with parameter value '{0}'", param)
    4. Throw exception with simple message and inner exception
    throw new CustomException(message, innerException)
    5. Throw exception with message format and inner exception. Note that, the variable length params are always floating.
    throw new CustomException("Exception with parameter value '{0}'", innerException, param)
    
    6. The last flavor of custom exception constructor is used during exception serialization/deserialization.
  • 相关阅读:
    荧光机理的应用——光学式农药测量技术及系统设计
    滤光片应用——红外吸收粉尘传感器的设计
    磁靶向纳米Fe3O4-TiO2复合物对肝癌细胞的光催化杀伤效应研究
    常用荧光染料的激发波长和发射波长
    光害
    一文解读虚拟化服务器
    一文解读PRA
    主数据建设的挑战与发展
    数字孪生技术变革
    intellij idea:配置maven 3.8.2(intellij idea 2021.2)
  • 原文地址:https://www.cnblogs.com/zeroone/p/3292415.html
Copyright © 2011-2022 走看看