Archive

Posts Tagged ‘.Net’

Custom Exception

March 31, 2009 Leave a comment

When you develop a n-tier application, it is quite common to create a custom exception class to inform the upper level application layers from an error.

The followings are the list of the important (in my opinion) things to be  considered for creating such a class. 

public class NewException : BaseException, ISerializable
{
    public NewException()
    {
        // Add implementation.
    }
    public NewException(string message)
    {
        // Add implementation.
    }
    public NewException(string message, Exception inner)
    {
        // Add implementation.
    }

    // This constructor is needed for serialization.
   protected NewException(SerializationInfo info, StreamingContext context)
   {
        // Add implementation.
   }
}

References: 

  1. Designing Custom Exceptions: 
    http://msdn.microsoft.com/en-us/library/ms229064.aspx
  2. Design Guidelines for Exceptions
    http://msdn.microsoft.com/en-us/library/ms229014.aspx