title: Catching null pointer exceptions
body: <p>I'm asking this mainly about Java, but I guess it applies to a whole host of languages.</p>
  
  <p>Consider,</p>
  
  <pre><code>if(myVariable==null){
      doSomethingAboutIt();
  }
  else carryOn(myVariable);
  </code></pre>
  
  <p>and</p>
  
  <pre><code>try{
      carryOn(MyVariable);
  }
  catch(NullPointerException e ){
        doSOmethingAboutIt();
  }
  </code></pre>
  
  <p>Are both these code blocks essentially the same? Is there any reason to choose the second approach? Of course, it would be better if myVariable was never null, but it seems that the best way to check for it is to do a simple if-statement.</p>