title: Returning true or false or throwing an exception
body: <pre><code>java version "1.7.0_75"
  </code></pre>
  
  <p>Hello,</p>
  
  <p>Just wondering what is the prefered best practice comparing the 2 functions below.</p>
  
  <p>The first one throws a NullPointerException that should be captured in the calling function.
  The second one just returns false if there has been a null pointer exception.</p>
  
  <p>Throw an exception:</p>
  
  <pre><code>public void disconnect() throws NullPointerException {
      if(mClientConnection == null) {
          throw new NullPointerException("mClientConnection has an invalid reference");
      }
  
      if(mClientConnection.isConnected()) {
          mClientConnection.disconnect();
      }
  
      mClientConnection = null;
  }
  </code></pre>
  
  <p>Just return true or false:</p>
  
  <pre><code>public boolean disconnect() {
      if(mClientConnection == null) {
          log.log(Level.SEVERE, "Cannot disconnect as mClientConnection is null");
          return false;
      }
  
      if(mClientConnection.isConnected()) {
          mClientConnection.disconnect();
      }
  
      mClientConnection = null;
  
      return true;
  }
  </code></pre>
  
  <p>Normally in the past I have always gone with the second one by just return true or false. But so now I am just looking for alternative solutions.</p>
  
  <p>Many thanks for any suggestions,</p>