Click here to Skip to main content
15,861,125 members
Articles / Web Development / ASP.NET

MVC Basic Site: Step 2 - Exceptions Management

Rate me:
Please Sign up or sign in to vote.
4.90/5 (46 votes)
25 Oct 2013Ms-PL16 min read 144.8K   5.4K   135  
This second article from the "MVC Basic Site" series presents in details the exceptions management rules and their implementation for an ASP.NET MVC web site, and provides some utile base classes and source code for Logging and Exceptions Management that can be reused.
using System;
using System.Runtime.Serialization;

namespace MvcBasic.Logic
{
    /// <summary>
    /// Defines the basic class for all exceptions used in MVC Basic Site solution.
    /// </summary>
    [Serializable]
    public class MvcBasicException : ApplicationException
    {

        /// <summary>
        /// Initializes a new instance of the MvcBasicException class with a specified error message.
        /// </summary>
        /// <param name="message">The message that describes the error.</param>
        public MvcBasicException(string message)
            : base(message)
        {
        }

        /// <summary>
        /// Initializes a new instance of the MvcBasicException class with a specified error message 
        /// and a reference to the inner exception that is the cause of this exception.
        /// </summary>
        /// <param name="message">The error message that explains the reason for the exception.</param>
        /// <param name="inner">The exception that is the cause of the current exception. 
        /// If the innerException parameter is not a null reference, the current exception is raised 
        /// in a catch block that handles the inner exception.</param>	
        /// <remarks>
        /// An exception that is thrown as a direct result of a previous exception should include 
        /// a reference to the previous exception in the InnerException property. 
        /// The InnerException property returns the same value that is passed into the constructor, 
        /// or a null reference if the InnerException property does not supply the inner exception 
        /// value to the constructor.
        /// </remarks>			
        public MvcBasicException(string message, Exception inner)
            : base(message, inner)
        {
        }

        /// <summary>
        /// Initializes a new instance of the MvcBasicException class with serialized data.
        /// </summary>
        /// <param name="info">The object that holds the serialized object data.</param>
        /// <param name="context">The contextual information about the source or destination.</param>
        protected MvcBasicException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
Romania Romania
I have about 20 years experiences in leading software projects and teams and about 25 years of working experience in software development (SW Developer, SW Lead, SW Architect, SW PM, SW Manager/Group Leader).

Comments and Discussions