C # custom exception

Custom exception

C # provides a wealth of exception classes, but in order to meet some other requirements, only a custom exception class. Today we define this exception class to add functionality is simple, that is, into exception information can be printed to the log.

So the code is as follows:

[Serializable]
    public class PFTException : Exception
    {
        public PFTException()
        {
        }

        public PFTException(string message)
            : base(message)
        {
            PFTLog.Error(message, () => { });
        }

        public PFTException(string messageFormat, params object[] args)
            : base(string.Format(messageFormat, args))
        {
            PFTLog.Error(string.Format (MessageFormat, args), () => {}); 
        } public PFTException ( String Message, the innerException Exception) 
            : Base (Message, the innerException) 
        { // record only the most primitive Exception information IF ((the innerException! IS PFTException )) 
            { 
                PFTLog.Error (Message, the innerException, () => {}); 
            } 
        } /// <Summary> /// deserialization constructor implemented ISerialization required to interface. /// </ Summary> /// <param name = "info"> </ param> /// <param name = "context"> </ param> Private

        
            
            


        
        
        
        
        
        PFTException (the SerializationInfo info, StreamingContext context): Base (info, context) 
        { // StringInfo = info.GetString ( "the StringInfo"); 
        } /// <Summary> /// GetObjectData override method. If you add custom fields, must override base class methods to achieve GetObjectData /// </ Summary> /// <param name = "info"> </ param> /// <param name = "context"> </ param> public the override void the GetObjectData (the SerializationInfo info, StreamingContext context) 
        { // custom serialization data member //info.AddValue("StringInfo ", StringInfo); // call the base class method, the sequence of its members base .GetObjectData (info, context); 
        } 
    }
            

        
        
        
        
        
          
            
            

            
            

Log method which can be seen [before I realized Log4Net logging ], when we throw PFTException direct information, we will save the information to a log message inside, if it is with Exception, Exception is to determine whether PFTException itself, If not, it means abnormal based systems, which also need to record the information into the log.

Guess you like

Origin www.cnblogs.com/snailblog/p/11530629.html