Java - Custom Exceptions
What will be the output of this code snippet?
class MyException extends Exception {}
public class Demo {
static void test(int val) throws MyException {
if (val == 0) throw new MyException();
System.out.println("Value: " + val);
}
public static void main(String[] args) {
try {
test(10);
test(0);
} catch (MyException e) {
System.out.println("Exception caught");
}
}
}