Java - Custom Exceptions
What will be the output of the following Java code?
class MyException extends Exception {
public MyException(String message) {
super(message);
}
}
public class Test {
public static void check(int num) throws MyException {
if (num < 0) {
throw new MyException("Negative number not allowed");
} else {
System.out.println("Number is " + num);
}
}
public static void main(String[] args) {
try {
check(-5);
} catch (MyException e) {
System.out.println(e.getMessage());
}
}
}