title: Java exception try-catch Exception vs IOException
body: <p>The following code compiles ok even though the try block doesn't actually throw any Exception.</p>
  
  <pre><code>public static void main(String[] args)  {
      try {} 
      catch (Exception e) {} // compiles ok
  }
  </code></pre>
  
  <p>But if the catch is replaced with a sub-class of Exception, the code won't compile. </p>
  
  <pre><code>public static void main(String[] args)  {
      try {} 
      catch (IOException e) {} // won't compile. 
  }
  </code></pre>
  
  <p>The compiler error is: Unreachable catch block for IOException. This exception is never thrown from the try statement body.</p>
  
  <p>How come this behavior when both Exception &amp; IOException are checked exceptions? I'm using Java 7.</p>