Java - Custom Exceptions
Consider this code snippet:
What will be the output?
class MyException extends Exception {
public MyException(String msg) { super(msg); }
}
public class Main {
static void validate(int age) throws MyException {
if (age < 18) throw new MyException("Age must be 18 or older");
}
public static void main(String[] args) {
try {
validate(16);
} catch (MyException e) {
System.out.println(e.getMessage());
}
}
}What will be the output?
