C# how TOO USE exception handling divided by zero expression


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace exception_handling_1
{
    class Program
    {
        static void Main(string[] args)
        {

           start :

            Console.WriteLine("WELCOME TOO EXCEPTION HANDLING");
            try
            {

                float a, b,result;
                Console.WriteLine("enter your first number");
                a = float.Parse(Console.ReadLine());
                Console.WriteLine("enter second number");
                b = float.Parse(Console.ReadLine());
                if (b == 0)
                {

                    throw new DivideByZeroException();

                }
                else
                    result = a / b;
                Console.WriteLine("your ans is after division : {0}", result);
            }
           
            catch
            {

                Console.WriteLine("SORRY  Number can't divide by zero ");

            }
            finally {

                Console.WriteLine("thankx for using our calculator");
           
            }
            goto start;

        

        }
    }

}

OUTPUT

No comments:

Post a Comment