Skip to main content

C#: Program #25 (Exceptional Handling)

using System;

namespace Exceptional_Handling
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 10;
            int b = 0;
            try
            {
                Console.WriteLine("10/0 is:{0}", Division(a, b));

            }
            catch (DivideByZeroException ex)
            {
                Console.WriteLine("Division by zero leads to infinity which is undefined and your values throws {0} because you {1}", ex.GetType().Name, ex.Message);
            }

            finally
            {
                Console.WriteLine("Subscribe my youtube Channel Gray Frost");
            }

            Console.ReadKey();
        }

        static int Division(int numerator,int denominator)
        {

            if (denominator == 0)
            {
                throw new System.DivideByZeroException();

            }
           
                return (numerator / denominator);


        }
    }
}

Comments

Popular posts from this blog

C#: Program #15 (For Loop)

using System; namespace Loops {     class Program     {         static void Main(string[] args)         {                         object[] information = {"Gray", "14-Arid-4052", "Rawalpindi",21,3.80};             for (int i = 0; i < information.Length; i++)             {                 Console.WriteLine("The value of index {0} is {1}",i,information[i]);             }                 Console.ReadKey();         }     } }