In calling method why Exception can be caught without throwing and why subclass of exception cannot be caught without throwing
<p>Catching an exception for a method which does not throw a subclass of exception in try block, fails to compile. when I catch Exception it works. How does it work??</p>

<p>This code below does not compile !! </p>

<pre><code>class Test
{
    public static void main(String[] args) {
        try {
            myMethod();
        } catch(MyException ex) {//Does not compile
        }
    }

    public static void myMethod() {}
}
</code></pre>

<p>class MyException extends Exception {}</p>

<hr>

<p>But when Exception is caught, compiler does not complain.</p>

<pre><code>class test
{
    public static void main(String[] args)
    {
        try{
            myMethod();
        } catch(Exception ex) {//how does this works ??
        }
    }

    public static void myMethod() {}
}
</code></pre>