hi all,i have written a code which shows exception when the age is less than 18 or greater than 22,its working perfectly.But now i want to enter the age during runtime,will someone change the code and give me.Thank u!
class userException extends Exception { int age; userException(int age) { age=age; } public String toString() { return"UserException caught:invalid age"; }} class userExceptionDemo { static void calculate(int age) throws userException { if(age<18||age>22) throw new userException(age); System.out.println("valid age"); } public static void main(String args[]) { try { calculate(20); calculate(34); } catch(userException obja) { System.out.println("caught:"+obja); } } }