title: Error Handler Servlet: how to get exception cause
body: <p>I have an error servlet configured in my web.xml:</p>
  
  <pre><code>&lt;error-page&gt;
      &lt;exception-type&gt;java.lang.Exception&lt;/exception-type&gt;
      &lt;location&gt;/ExceptionHandler&lt;/location&gt;
  &lt;/error-page&gt;
  </code></pre>
  
  <p>right?</p>
  
  <p>In my (generically) servlet:</p>
  
  <pre><code>doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      try {
          ...
          ...
      } catch (Exception e) {
          throw new ServletException("some mesage", e);
      }
  }
  </code></pre>
  
  <p>so, "e" will be the root cause in this case.</p>
  
  <p>In my ExceptionHandler class, I have:</p>
  
  <pre><code>doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      Throwable throwable = (Throwable) request.getAttribute("javax.servlet.error.exception");
      throwable.getCause() //NULL
  }
  </code></pre>
  
  <p>this is the problem. throwable.getCause() is null.</p>