00:00
import java.util.Scanner;
class YoungerAgeException extends RuntimeException{
YoungerAgeException(String msg){
super(msg);
}
}
class L39vOTE{
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");
}
else{
System.out.println("you can vote");
}
}
catch(YoungerAgeException e){ // insted of Exception
e.printStackTrace();
}
System.out.println("voting process done successfully");
}
}
// is case me jo exception object programmer ne create kare hai
// usko catch block handle kar leyga
// aur normal aage ka program bhee execute ho jayga.
/*
ramannegi@Ramans-MacBook-Pro x % javac L39vOTE.java
ramannegi@Ramans-MacBook-Pro x % java L39vOTE
enter your age
15
YoungerAgeException: you are not elligible for voiting
at L39vOTE.main(L39vOTE.java:15)
voting process done successfully
*/