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