21CSL582 Program 4

4. Develop a C# program to demonstrate Division by Zero and Index Out of Range exceptions.

using System;
public class Divide
{
    public static void Main(string[] args)
    {
        try
        {
            int result = 15 / int.Parse("0");
            System.Console.WriteLine(result);
        }
        catch (DivideByZeroException e)
        {
            System.Console.WriteLine(e.Message);
            System.Console.ReadLine();
        }
    }
}
****************OUTPUT1****************

Attempted to divide by zero.



****************OUTPUT2****************

15

Leave a Reply

Your email address will not be published. Required fields are marked *