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