Search...

Tuesday, April 2, 2013

Creating Custom Exceptions in c#


using System;
using System.Runtime.Serialization;  

    /// <summary>
    ///  This Class is used to call the Interaction logic for CustomException.
    /// </summary>
    /// <Developer>Kaushik Kumar Mistry</Developer>
    /// <DateCreated>02 April 2012</DateCreated>
    [Serializable]
    public class CustomException : Exception
    {

        #region <<  Constructors  >>

        /// <summary>
        /// Throw exception with out message
        /// </summary>
        public CustomException()
            : base() { }

        /// <summary>
        /// hrow exception with simple message
        /// </summary>
        /// <param name="message"></param>
        public CustomException(String message)
            : base(message) { }

        /// <summary>
        /// Throw exception with message format and parameters
        /// </summary>
        /// <param name="format"></param>
        /// <param name="args"></param>
        public CustomException(String format, params object[] args)
            : base(String.Format(format, args)) { }

        /// <summary>
        /// Throw exception with simple message and inner exception
        /// </summary>
        /// <param name="message"></param>
        /// <param name="innerException"></param>
        public CustomException(String message, Exception innerException)
            : base(message, innerException) { }

        /// <summary>
        /// Throw exception with message format and inner exception. Note that, the variable length params are always floating.
        /// </summary>
        /// <param name="format"></param>
        /// <param name="innerException"></param>
        /// <param name="args"></param>
        public CustomException(String format, Exception innerException, params object[] args)
            : base(String.Format(format, args), innerException) { }

        /// <summary>
        /// The last flavor of custom exception constructor is used during exception serialization/deserialization.
        /// </summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        protected CustomException(SerializationInfo info, StreamingContext context)
            : base(info, context) { }

        #endregion
    }

No comments: