title: how to handle unchecked exceptions?
body: <p>I'm having difficulties understanding how to handle unchecked exceptions.</p>
  
  <p>If the method doesn't declare the exception and I am not forced to handle it, how do I even know the method throws an exception?</p>
  
  <p>Unchecked exceptions are for programming errors, as I have read, so to avoid a <code>NullPointerException</code>, I would introduce a null check. Or for an <code>ArrayIndexOutOfBoundsException</code> I would check how I access the array.</p>
  
  <p>But when I don't know that a method throws a custom unchecked exception, how am I supposed to handle this?</p>
  
  <p>And how do you propagate exceptions from the data layer to the user interface? Those must be checked exceptions, right?</p>
  
  <p>I would let the data layer throw checked <code>DataLayerExceptions</code> and then have a try-catch-block in the presenter class (given I am using MVP) and then in the catch-block set the error message on the view...</p>
  
  <p>Or can this be done using unchecked exceptions?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Thanks for the replies so far.</p>
  
  <p>Here is a concrete example I am faced with.</p>
  
  <p>I am getting started with Spring and in a book I saw a <code>UserRepository</code> class that uses a <code>JDBCTemplate</code> to retrieve data from the database. The <code>UserRepositoty</code> contains a method somewhat like this:</p>
  
  <pre><code>@Override
  public List&lt;User&gt; findAll() {
      String sql = "select id, username, email, password from p_user";
      return new ArrayList&lt;&gt;(jdbcTemplate.query(sql, rowMapper));
  }
  </code></pre>
  
  <p>Now, the query method of the jdbcTemplate throws a <code>DataAccessException</code>, which is a runtime exception.</p>
  
  <p>I knwo this, because I looked at the method signature.</p>
  
  <p>Now, how would I handle this exception? Surely, the user needs some type of feedback that something went wrong. And surely, I would log the exception.</p>
  
  <p>But where would I catch this exception? </p>
  
  <p>Should I catch it right there and then rethrow my own unchecked exception?
  Or should I declare a throws <code>DataAccessException</code> on the <code>findAll</code> method and then deal with the exception in the calling class (which may be a service or presenter of some sort)?</p>
  
  <p>Or should I make sure that the conditions under which the exception is thrown can never occur (in case those are even controllable by me)?</p>