Exception - All exceptions are derived from System.Exception Class .
its a one type of run time error.
There are two types of exception
1) System exception
2) Application Exception.
Example ;
public void Add()
{
try
{
int[] num =new int[4];
for(int i=0 ; i<10;i++)
{
num[i] =i ;
}
}catch( IndexOutOfRangeException ex)
{
Console.WriteLine("Standard message is: ");
Console.WriteLine(exc); // calls ToString()
Console.WriteLine("Stack trace: " + exc.StackTrace); // stack of call that leads to exception .
Console.WriteLine("Message: " + exc.Message); //string describe nature of error .
Console.WriteLine("TargetSite: " + exc.TargetSite); //method who generate excetoin .
Console.WriteLine("Class defining member: {0}", exc.TargetSite.DeclaringType);
Console.WriteLine("Member type: {0}", exc.TargetSite.MemberType);
Console.WriteLine("Source: {0}", exc.Source);
Console.WriteLine("Help Link: {0}", exc.HelpLink);
}
}
its a one type of run time error.
There are two types of exception
1) System exception
2) Application Exception.
Example ;
public void Add()
{
try
{
int[] num =new int[4];
for(int i=0 ; i<10;i++)
{
num[i] =i ;
}
}catch( IndexOutOfRangeException ex)
{
Console.WriteLine("Standard message is: ");
Console.WriteLine(exc); // calls ToString()
Console.WriteLine("Stack trace: " + exc.StackTrace); // stack of call that leads to exception .
Console.WriteLine("Message: " + exc.Message); //string describe nature of error .
Console.WriteLine("TargetSite: " + exc.TargetSite); //method who generate excetoin .
Console.WriteLine("Class defining member: {0}", exc.TargetSite.DeclaringType);
Console.WriteLine("Member type: {0}", exc.TargetSite.MemberType);
Console.WriteLine("Source: {0}", exc.Source);
Console.WriteLine("Help Link: {0}", exc.HelpLink);
}
}
No comments:
Post a Comment