class InvalidAgeException extends Exception { InvalidAgeException(String msg) { System.out.println(msg); } } class test { public static void vote(int age) throws InvalidAgeException { if(age<18) { throw new InvalidAgeException("not eligible for voting"); } else { System.out.println("Eligible for voting "); } } public static void main(String[] args){ try { vote(12); } catch(Exception d) { System.out.println(d); } } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter