Exception Handling in c# - C# Tutorials

Latest

For Video tutorials Visit my Channel https://www.youtube.com/channel/UCVWpZVbMqLHuQBigIfc9I8Q

Monday, 13 February 2017

Exception Handling in c#

using System;
namespace ErrorHandlingApplication
{
    class DivNumbers
    {
        int result;
        public DivNumbers()
        {
            result = 0;
        }
        public void division(int a, int b)
        {
            try
            {
               
                int[] student = new int[5];
                student[0] = 5;
                student[1] = 6;
                student[2] = 7;
                student[3] = 8;
                student[4] = 9;
                student[5] = 5;

                result = a / b;

            }
            catch (IndexOutOfRangeException e1)
            {
                Console.WriteLine("Exception Cought : {0}", e1);
            }
            catch (DivideByZeroException e2)
            {
                Console.WriteLine("Exception Cought : {0}", e2);
            }
           
            finally
            {
                Console.WriteLine("Result: {0}", result);
            }
        }
        static void Main(string[] args)
        {
            DivNumbers d = new DivNumbers();
            d.division(10, 0);           
            Console.ReadKey();
        }
    }

}

No comments:

Post a Comment