title: Why does Spring wrap RuntimeException in NestedServletException when handle endpoint exception?
body: <p>According to <a href="https://jcp.org/en/jsr/detail?id=340" rel="nofollow noreferrer">Servlet Specification</a>:</p>
  
  <blockquote>
    <p>A servlet or filter may throw the following exceptions during
    processing of a request:</p>
    
    <ol>
    <li>runtime exceptions or errors </li>
    <li>ServletExceptions or subclasses thereof</li>
    <li>IOExceptions or subclasses thereof</li>
    </ol>
  </blockquote>
  
  <p>If we look at <code>org.springframework.web.servlet.FrameworkServlet#processRequest</code>, we'll see that Spring throws <code>ServletException</code> and <code>IOException</code>, but wraps others including <code>RuntimeExceptions</code>:</p>
  
  <pre><code>try {
      doService(request, response);
  } catch (ServletException | IOException ex) {
      failureCause = ex;
      throw ex;
  } catch (Throwable ex) {
      failureCause = ex;
      throw new NestedServletException("Request processing failed", ex);
  }
  </code></pre>
  
  <p>Why doesn't Spring handle <code>RuntimeException</code> like <code>IOException</code>?</p>
  
  <p><strong>UPD</strong>: In other words, what wrong would happen if they handle exceptions this way:</p>
  
  <pre><code>try {
      doService(request, response);
  } catch (ServletException | IOException | RuntimeException ex) {
      failureCause = ex;
      throw ex;
  } catch (Throwable ex) {
      failureCause = ex;
      throw new NestedServletException("Request processing failed", ex);
  }
  </code></pre>