What are Custom Exceptions? - C#.NET

What are Custom Exceptions?

Custom Exceptions are user defined exceptions.

There are exceptions other than the predefined ones which need to be taken care of.

For example: The rules for the minimum balance in a Salary A/C would be different from that in a Savings A/C due to which these things need to be taken care of during the implementation.

Custom exception needs to derive from the System.Exception class. You can either derive directly from it or use an intermediate exception like SystemException or ApplicationException as base class. Custom exceptions are created to handle very specific exceptions and to provide more details about it.

We need custom exceptions to have better predictability of our application. By using custom exceptions we can throw and handle our own exceptions, providing a much more predictable and stable application.
public class MyCustomException : Exception
{
   public MyCustomException()
   : base()
   {
   }

   public MyCustomException(string Message)
   : base(Message)
   {
   }

   public MyCustomException(string Message, Exception InnerException)
   : base(Message, InnerException)
   {
   }

   protected MyCustomException(SerializationInfo Info, StreamingContext Context)
   : base(Info, Context)
   {
   }
}
What are delegates and why are they required? - C#.NET
What are delegates and why are they required? - The delegates in .NET are like the pointers to the functions in C/C++...
How to implement Delegates in C#.NET
Explain how to implement Delegates in C#.NET - Here is an implementation of a very simple delegate that accepts no parameters...
C#.NET - CLR Triggers
A CLR trigger could be a Date Definition or Date Manipulation Language trigger or could be an AFTER or INSTEAD OF trigger...
Post your comment