What are Custom Exceptions? Why do we need them? - C#.NET

Explain how to Handle Exceptions in .NET 2.0.

The different methods of handling the exceptions are:
1.
try
{
    // code
}
catch(Exceptiontype *etype_object)
{
    // code
}

2.
try
{
    // code
}
catch(Exceptiontype *etype_object)
{
    throw new Custom_Exception();
}


Exceptions should never be handled by catching the general System.Exception errors, rather specific exceptions should be caught and handled.

They are handled using try catch and finally. Finally is used to cleanup code as it's always executed irrespective of whether an exception has occurred or not.
Example
try
{
    FileInfo file=new FileInfo(@"c:\abc.txt")
}
   catch(FileNotFoundException e)
   {
       //handle exception
   }
   Finally
   {
       //cleanup code here
   }
If file is found, then finally will get invoked else both catch and finally will occur.
What are Custom Exceptions? - C#.NET
What are Custom Exceptions? - Custom exception needs to derive from the System.Exception class. You can either derive directly from it or use an intermediate exception like SystemException...
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...
Post your comment