class InvalidAgeException extends Exception {
private static final long serialVersionUID = 1L;
InvalidAgeException(String s) {
super(s);
}
}
public class Custom {
public static void age(int age) throws InvalidAgeException {
if (age < 18)
throw new InvalidAgeException("not valid");
else
System.out.println("welcom to vote");
}
public static void main(String[] args) {
try {
age(19);
} catch (Exception ex) {
System.out.println("exception occured " + ex);
}
}
}
Comments