You are on page 1of 1

using using using using

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

namespace Lab4T6 { public class DivideByZeroException : Exception { public DivideByZeroException(string Message) : base(Message) { } public DivideByZeroException() { } public DivideByZeroException(string Message, Exception inner) : base(Message, inner) { } } public class MainApp { public static void Main() { double x,z=10; Console.WriteLine("***** Catch the Divide by zero Exception for z/x *****"); Console.WriteLine("Enter the value of x "); x = double.Parse(Console.ReadLine()); try { if (x == 0.00) { throw new DivideByZeroException("Enter number is negative !" ); } else Console.WriteLine("{0} / {1} = {2}", z, x, z / x); } catch (DivideByZeroException e) { Console.WriteLine("Caught Divide by Zero Exeption "); Console.WriteLine(e.Message); } Console.ReadKey(); } } }

You might also like