Wednesday, January 15, 2014

Exception Handling




PROBLEM STATEMENT
Make an exception in a program & handle it.

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

namespace exceptionhandling
{
    class arrayexception : Exception
    {
        public arrayexception() :
            base("please enter the command line arguement")
        {
        }
    }
    class throwarrayexception
    {
        public throwarrayexception(int a)
        {
            try { checksize(a); }
            catch (arrayexception ae)
            {
                Console.WriteLine(ae.Message);
            }
        }
        public void checksize(int a)
        {
            if (a == 0)
                throw new arrayexception();
            else
            {
                Console.WriteLine("the size of arguements passed to main method is {0}", a);
            }
        }
        class program
        {
            static void Main(string[] args)
            {
                new throwarrayexception(args.Length);
            }
        }
    }
}




OUTPUT:


No comments:

Post a Comment