00:00
import java.util.Scanner;
class YoungerAgeException extends RuntimeException{
YoungerAgeException(String msg){
super(msg);
}
}
class L37vOTE{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("enter your age");
int age = sc.nextInt();
if(age<18){
throw new YoungerAgeException("you are not elligible for voiting");
}
else{
System.out.println("you can vote");
}
System.out.println("voting process done successfully");
}
}
// class YoungerAgeException extends RuntimeException = must inherit parent c/L
// throw new YoungerAgeException("you are not elligible for voiting") = user create
// exception must pass to JVM ( for DEH ),
// and program abnormally terminate itself
//
/*
ramannegi@Ramans-MacBook-Pro x % javac L37vOTE.java
ramannegi@Ramans-MacBook-Pro x % java L37vOTE
enter your age
17
Exception in thread "main" YoungerAgeException: you are not elligible for voiting
at L37vOTE.main(L37vOTE.java:15)
*/