C# Program for Exception Handling using Finally Handling

Here is an example of finally handling in exceptional handling in c sharp………..
 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
    class AddNumbers
    {
        int result;
        AddNumbers()
        {
            result=0;
        }
        public void divide(int number1, int number2)
      
        {
            try
            {
                 result = number1 / number2;
               
            }
            catch (DivideByZeroException e)
            {
                Console.WriteLine(“Exception caught. {0}”, e);
            }
            finally
            {
                Console.WriteLine(“result is {0}”, result);
            }
        }
            public static void Main (string [] args)
            {
                AddNumbers Division = new AddNumbers();
                Division.divide(10,0);
                Console.ReadLine();
            }
    }
}
       

Add Comment