Sunday, 3 June 2018

Custom Exception in C# Error Handling



----------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication37
{
    class CustomEXception:Exception
    {
        public CustomEXception(string msg):base (msg)
        {

        }
       

    }
}


-----------------------------------------------------------------------------------------

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication37

{

    class Program

    {

        public static void checkage(int age)

        {

            if (age<18)

            {

                throw new CustomEXception("Age should be greater than 18...");

            }

            else

            {

                Console.WriteLine("Eligible to enrolled in exam....");

            }



        }

        static void Main(string[] args)

        {

         

            int age ;

        l1:

        Console.WriteLine("Enter the age: ");

        age = int.Parse(Console.ReadLine());

            try

            {

                checkage(age);

            }

            catch( CustomEXception e)

            {

                Console.WriteLine("error is "+e);

               // throw;

            }

         

            finally

            {



                Console.WriteLine("press any key to continue....");

                Console.ReadLine();

                Console.Clear();

            }



            goto l1;

        }

    }

}


No comments:

Post a Comment

Pass Dynamically Added Html Table Records List To Controller In Asp.net MVC

Controller Code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ...