title: Recover from a method throwing an exception
body: <p>I am fairly new to java esp. to some of the coding practices. I have a situation where a method throws a <code>NullPointerException</code> and the calling method catches it.</p>
  
  <pre><code>try {
      String test = Class.method(arg)
  }    
  catch (Exception ex) {
      ...
  }
  
  public String method(arg){
  String str;
  ...
  if(str == null) throw(exception)
  return str;
  }
  </code></pre>
  
  <p>Now some method inside <code>Class.method(arg)</code> throws a <code>NullPointerException</code> and it gets caught in the above catch (like above). Instead I want to do something like:</p>
  
  <pre><code>if (test == null) { do something else }
  </code></pre>
  
  <p>inside the try block.</p>
  
  <p>What is the best way to handle this? Can I remove the throw inside method and make it return null?</p>