title: How to catch a Thymeleaf (view) rendering exception with Spring?
body: <p>So far now, I've tried;</p>
  
  <p><strong>1)</strong> to create a bean which extends org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver and implement doResolveException(..) method (It was waste of time because it already returns ModelAndView). The code is below:</p>
  
  <pre><code> @Override
  protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
      response.setStatus(534);
      log.trace("exception from HandlerExceptionResolver");
      log.error(ex.getMessage(),ex);
  
      Client bugsnag = new Client(BUGSNAG_API_KEY);
  
      //bugsnag code omitted
  
      ModelAndView modelAndView=new ModelAndView("error");
      return modelAndView;
  }
  </code></pre>
  
  <p><strong>2)</strong> to create a bean which implements javax.servlet.Fiter and implement doFilter(..) method (It was waste of time, too. Because it already returns ModelAndView)</p>
  
  <pre><code> @Override
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
      try {
          filterChain.doFilter(request, response);
      } catch (Exception ex) {
          errorHandler.handleError(ex);
          log.trace("exception from HandlerExceptionResolver");
          log.error(ex.getMessage(),ex);
  
          Client bugsnag = new Client(BUGSNAG_API_KEY);
  
          //bugsnag code omitted
  
          RequestDispatcher error = request.getRequestDispatcher("error");
          error.forward(request,response);
      }
  }
  </code></pre>
  
  <p><strong>3)</strong> and the @ControllerAdvice annotation (this works all other exception except view exceptions like parsing)</p>
  
  <p>All 3 solutions didn't work for me to catch view exception and navigate to error page. I think there must be a solution in filter level. But i couldn't manage it. (That's why methods return ModelAndView object does not work)</p>
  
  <p>Any suggestion?</p>