Input
Output
public class ThrowsException { static void age() throws IllegalAccessException { int a=12; if(a>18) { System.out.println("Right to vote"); } else{ throw new IllegalAccessException("Not eligible"); } } public static void main(String args[]) { try { age(); } catch(IllegalAccessException e) { System.out.println("Exception handled"); } } }