title: Java - Return statement and thrown exception using method inside catch block?
body: <p>I have following code using hibernate to throw a custom exception on error and I also want to close the session in this case, since the exception won't be catched unless received on the client machine.</p>
  
  <pre><code>public &lt;T&gt; T get(final Session session, final String queryName) throws RemoteException
  {
      final Query query = // query using given session ...
  
      try
      {
          return (T) query.uniqueResult();
      }
      catch (final HibernateException e)
      {
          SessionManager.logger.log(Level.SEVERE, "Could not retrieve Data", e);
          this.closeSession(session);
          throw new RemoteException("Could not retrieve Data");
      }
  }
  </code></pre>
  
  <p>Now I have a helper method which closes the session and throws a given exception:</p>
  
  <pre><code>public void closeSessionAndThrow(final Session session, final RemoteException remoteException)
      throws RemoteException
  {
      this.closeSession(session);
      throw remoteException;
  }
  </code></pre>
  
  <p>Now I thought I could simplify my above code using:</p>
  
  <pre><code>public &lt;T&gt; T get(final Session session, final String queryName) throws RemoteException
  {
      final Query query = // query using given session ...
  
      try
      {
          return (T) query.uniqueResult();
      }
      catch (final HibernateException e)
      {
          SessionManager.logger.log(Level.SEVERE, "Could not retrieve Data", e);
          this.closeSessionAndThrow(session, new RemoteException("Could not retrieve Data"));
      }
  }
  </code></pre>
  
  <p><strong>Now</strong> I need to add a <code>return null;</code> statement after the catch. Why?</p>