using System.Text.RegularExpressions;
public class ValidationException : Exception
public ValidationException(string message): base(message)
Console.WriteLine("Object is being created");
public void validate(string n, string e, int a)
if (Regex.Match(n, "^[A-Z][a-zA-Z]*$").Success)
throw new ValidationException("Name must contain only characters");
throw new ValidationException("Age between 18 and 99");
if (Regex.Match(e, @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$").Success)
throw new ValidationException("Invalid Email Format");
Console.WriteLine(email);
public static void Main()
Validator a = new Validator();
a.validate("Jay", "jj@j.in", 21);
catch (ValidationException e)