Wednesday 22 August 2012


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

namespace ErrorDemo
{
    class ErrorDemo
    {
        public static void Main(String[] args)
        {
            int a, b, ans;
            int[] no = new int[5];
            try
            {
                a = int.Parse(args[0]);
                b = 10;
                ans = b / a;
                Console.WriteLine("ans=" + ans);
                no[4] = ans;
                Console.WriteLine(no[3]);
            }
            catch (DivideByZeroException e)
            {
                Console.WriteLine("Division by 0");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine("After try catch block");
            Console.ReadKey();      
        }
    }
}

No comments:

Post a Comment