00:00
import java.util.Scanner;
class YoungerAgeException extends RuntimeException{
YoungerAgeException(String msg){
super(msg);
}
}
class L40vOTE{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("enter your age");
int age = sc.nextInt();
try{
if(age<18){
throw new YoungerAgeException("you are not elligible for voiting");
System.out.println("dont make any statement after throw");
}
else{
System.out.println("you can vote");
}
}
catch(YoungerAgeException e){ // insted of Exception
e.printStackTrace();
}
System.out.println("voting process done successfully");
}
}
// throw ke baad koi bhe statement nahe ayegee
/*
ramannegi@Ramans-MacBook-Pro x % javac L40vOTE.java
L40vOTE.java:16: error: unreachable statement
System.out.println("dont make any statement after throw");
^
*/