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;

        }

    }

}


Finally block in Exception handling in C#



using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication36

{

    class Program

    {

        static void Main(string[] args)

        {



            int a, b;

            float c;

         

            l1:

            Console.WriteLine("Enter the value of a :");

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



            Console.WriteLine("Enter the value of b :");

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



            try

            {

                c =(float) (a *1.0 / b);

                Console.WriteLine("value of c =" + c);

            }

            catch (Exception e)

            {

                Console.ForegroundColor = System.ConsoleColor.Red;



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

            }



            finally

            {

                Console.ForegroundColor = System.ConsoleColor.White;

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

                Console.ReadKey();

                Console.Clear();

             

            }



            goto l1;



       

        }

    }

}


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 ...