Exceptions Handling Program in C#(Sharp)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TrappedExceptions
{
class Program
{
static void Main(string[] args)
{
// Exceptions trapped Program
try{ // using try... catch
int first, second;
Console.Write("Enter the first number=>");
first = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the second number=>");
second = Convert.ToInt32(Console.ReadLine());
int result = first/second;
Console.WriteLine(result);
Console.ReadLine();
}catch(Exception)
{
Console.WriteLine("Divide by Zero error");// if value is Divide by Zero.
Console.ReadLine();
}
}
}
}
No comments:
Post a Comment