public class CustomAgeExceptionn extends Exception{
CustomAgeExceptionn(){
}
CustomAgeExceptionn(String s){
super(s);
}
public String checkAge(int a) throws CustomAgeExceptionn {
if(a<18) {
throw new CustomAgeExceptionn("You are not elagble for vote!!");
}
else {
return "Welcome !! ";
}
}
public static void main(String[] args) {
CustomAgeExceptionn ob=new CustomAgeExceptionn();
String s;
try {
s = ob.checkAge(20);
System.out.println(s);
} catch (CustomAgeExceptionn e) {
e.printStackTrace();
}
}
}
Comments
Post a Comment