System.Exception Namespace

Here i am explaining about System.Exception namespace.
  • 2749
Introduction

Exception handling is an important feature of C# language. Exception handling is used for catching the exception which occurred in the programs. In exception handling it provide three features which are given below

  • try block
  • catch block
  • finally 

To handle these exception c# developer provide System.Exception namespace. It provide essential classes and methods which are required to handle exceptions.

Properties of Exception class

  • Data
  • HelpLink
  • HResult
  • InnerException
  • Message
  • Source
  • TargetSite

Example :

using System;
using
 System.Collections.Generic;
using
 System.Linq;
using
 System.Text;
 

namespace
 ConsoleApplication1
{
    class 
Vipendra
    {
        static void show(string a)
        {
            if (a == null)
            {
                throw new ArgumentNullException();
            }
        }
        static void Main(string[] args)
        {
 
            
try
            {
                string a = null;        
                show(a);               
            }
            catch (Exception e)
            {
                Console.WriteLine("{0} Exception caught.", e);
                Console.ReadLine();
            }
 
            
finally
            {        

                Console.WriteLine("Executing finally block.");
                Console.ReadLine();
                
           }
        }
    }
}

Output :

Clipboard02.jpg

 

  
© 2019 DotNetHeaven. All rights reserved.