divide by zero exception handling

Raj_Chennai
Posted by Raj_Chennai under C# category on | Points: 40 | Views : 3000
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace dividebyzero
{
class Program
{
static void Main(string[] args)
{
int v2, v1,v3;

try
{
Console.WriteLine("Enter the number to perform divide operation");
v1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the number by which divide operation is to be performed");
v2= Convert.ToInt32(Console.ReadLine());
v3 = v1 / v2;

Console.WriteLine("Result is {0}", v3);


}
catch(DivideByZeroException de)
{
Console.WriteLine("Division by Zero occurs"+de);
}
finally
{
Console.WriteLine("Task completed");
Console.ReadLine();
}
}
}
}

Comments or Responses

Login to post response