title: java - checked exception for 'throws' in overridden method
body: <p>I was practicing exception handling mechanisms with method overriding in java...My code is as follows:</p>
  <pre><code>class base {
      void show() {    
          System.out.println(&quot;in base class method&quot;);    
      }
  }
  
  class derived extends base {
      void show() throws IOException {    
          System.out.println(&quot;in derived class method&quot;);
          throw new IOException();
      }
  }
  
  class my {
      public static void main(String[] args) {  
          try {
              base b = new derived();
              b.show();
          }    
          catch (IOException e) {
              System.out.println(&quot;exception occurred at :&quot; + e);
          }   
      }
  }
  </code></pre>
  <p>Showing an error :</p>
  <p><img src="https://i.stack.imgur.com/YNDaY.png" alt="cmd window" /></p>
  <p>So, I corrected following:</p>
  <pre><code>void show() throws IOException{
  </code></pre>
  <p>and it is working correctly...</p>
  <p>One more experiment I did :</p>
  <pre><code>void show() throws Exception{
  </code></pre>
  <p>but it was also showing an error:</p>
  <p><img src="https://i.stack.imgur.com/KxUhS.png" alt="cmd window" /></p>
  <p>As I understand, this is because of an overridden method's <code>throws</code> clause should mention the exact checked exception in <code>throws</code> clause of super class method.</p>
  <p>As in second case, if I write <code>IOException</code>'s superclass <code>Exception</code> in throws clause, it also shows an error.  why? Even if <code>Exception</code> is parent class of all exceptions.</p>
  <p>I just experimented...what this error tells I don't know...</p>
  <p>Can any one please explain what it says and what are the constraints for mentioning checked exception in <code>throws</code> clause of an overridden method?</p>