doubt in Exceptions
- by Ajay Singh
class MyException extends Exception {
    MyException() {}
    MyException(String msg) { super(msg);}
}
public class NewException {
    static void f() throws MyException {
        System.out.println("throwing exception from f()");
        throw new ClassCastException();
    }
    static void g() throws MyException {
        System.out.println("throwing exception from g()");
        throw new MyException("parametrized ");
    }
    public static void main(String ...strings ) {
        try { 
            f();
        }
        catch(MyException e) {
            e.printStackTrace(System.out);
        }
        try {
            g();
        }
        catch(MyException e) {
            e.printStackTrace(System.out);
        }
    }
}
In the function f() iam specifying that "MyException " exception will be thrown and actually iam throwing some other exception which has no relation with MyException but still the compiler does not report any complain.Why is it so??