title: Why can I throw null in Java?
body: <p>When running this:</p>
  
  <pre><code>public class WhatTheShoot {
  
      public static void main(String args[]){
          try {
              throw null;
          } catch (Exception e){
              System.out.println(e instanceof NullPointerException);
              System.out.println(e instanceof FileNotFoundException);
          }
      }
  }
  </code></pre>
  
  <p>The response is:</p>
  
  <pre><code>true  
  false
  </code></pre>
  
  <p>Which was fairly stunning for me. I would have thought this would net a compile-time error. </p>
  
  <p><strong>Why can I throw null in Java, and why does it upcast it to a NullPointerException?</strong></p>
  
  <p><em>(Actually, I don't know if it is an "upcast", given I'm throwing null)</em></p>
  
  <p>Aside from a really really stupid interview question (please nobody ask this in an interview) I cannot see any reason to <code>throw null</code>. Maybe you want to be fired, but that's... I mean, why else would anyone <code>throw null</code>?</p>
  
  <p><strong>Fun fact</strong> <a href="http://en.wikipedia.org/wiki/IntelliJ_IDEA" rel="noreferrer">IntelliJ IDEA</a> 12 tells me that my line, <code>e instanceof NullPointerException</code>, will always be false. Which isn't true at all.</p>