Sunday, 13 April 2014

Custom Exception

Custom Exception User Defined Exception:
class TooYoungExceptionDemo extends RuntimeException
{
TooYoungExceptionDemo(String str)
{
super(str);

}

};
class CEDemo
{
public static void main(String[] args)
{
int age= Integer.parseInt(args[0]);
        if (age<18)
{throw new TooYoungExceptionDemo("sorry! wait 4 some time");
}

else if(age>50)
{
throw new TooYoungExceptionDemo("sorry! u r not elible");
}System.out.println("sorry! egt good match");


}
}

No comments:

Post a Comment