title: Handle org.thymeleaf.exceptions.TemplateInputException
body: <p>I have the following controller logic. However, if I navigate to a non-existing page (e.g. /random-page), I end up with a TemplateInputException. How can I catch this and go to the 404 page?</p>
  
  <pre><code>@RequestMapping(value = { "{path:(?!resources|error).*$}", "{path:(?!resources|error).*$}/**" }, headers = "Accept=text/html")
  public String index(final HttpServletRequest request) {
      try {
          String path = (String) request.getAttribute(
                  HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
          return path.split("/")[1];
      } catch (Exception e) {
          log.error("Failed to render the page. {}",e);
          return "error/general";
      }
  }
  </code></pre>
  
  <p>Thymeleaf seems to be ignoring the ExceptionHandler:</p>
  
  <pre><code>@ExceptionHandler(Exception.class)
  public ModelAndView handleAllException(Exception ex) {
  
      ModelAndView model = new ModelAndView("error/generic_error");
      model.addObject("errMsg", "this is Exception.class");
  
      return model;
  
  }
  </code></pre>