Exception :-
The Exception is one type of error which comes from the system or currently executed application throws that which normally contains the information about the error .
Exception Handling is the mechanism provided by the c sharp language to handle that type of exception .
See The Below Example Which Contains the Try,Catch,Throw and finally blocks.
class Program
{
static void Main(string[] args)
{
double a=100,result = 0;
double b = 0;
// double b = 10; //Please check it by removing comment and Give comment to above statement
try
{
result = div(a, b);
Console.WriteLine("The division of {0} and {1} is {2}", a, b, result);
}
catch (Exception e)
{
//Console.WriteLine(e.ToString());
Console.WriteLine("Exception Divide by Zero is Handled");
}
finally
{
Console.WriteLine("This is finally block statement");
}
Console.ReadLine();
}
public static double div(double a1, double b1)
{
if (b1 == 0)
{
throw new System.DivideByZeroException();
}
else
{
return a1 / b1;
}
}
}
The Exception is one type of error which comes from the system or currently executed application throws that which normally contains the information about the error .
Exception Handling is the mechanism provided by the c sharp language to handle that type of exception .
See The Below Example Which Contains the Try,Catch,Throw and finally blocks.
class Program
{
static void Main(string[] args)
{
double a=100,result = 0;
double b = 0;
// double b = 10; //Please check it by removing comment and Give comment to above statement
try
{
result = div(a, b);
Console.WriteLine("The division of {0} and {1} is {2}", a, b, result);
}
catch (Exception e)
{
//Console.WriteLine(e.ToString());
Console.WriteLine("Exception Divide by Zero is Handled");
}
finally
{
Console.WriteLine("This is finally block statement");
}
Console.ReadLine();
}
public static double div(double a1, double b1)
{
if (b1 == 0)
{
throw new System.DivideByZeroException();
}
else
{
return a1 / b1;
}
}
}
The perfect Example of Exception Handling.
ReplyDelete