Tuesday, 10 March 2020

How to create Custom Exception in C# ?



The code snippet is given as below.


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

namespace CustomExceptionInCsharp
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                int res = checkAGE();
                Console.WriteLine(res);
                Console.ReadLine();
            }
            catch (CustomEx_AGE ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        static int checkAGE()
        {
            Console.WriteLine("Enter AGE:");
            int age = Convert.ToInt32(Console.ReadLine());
            if (age<18 18="" :="" above="" age="" base="" be="" class="" customex_age="" exception="" msg="" new="" pre="" public="" return="" should="" string="" throw="">

About the Author

Admin

Author & Editor

Has laoreet percipitur ad. Vide interesset in mei, no his legimus verterem. Et nostrum imperdiet appellantur usu, mnesarchum referrentur id vim.

0 comments:

Post a Comment

 

Technical Talks © 2015 - Designed by Templateism.com, Distributed By Blogger Templates