title: How to use @ExceptionHandler in Spring Interceptor？
body: <p>I am using springmvc to create restful api for client， I have an interceptor for checking the accesstoken.</p>
  
  <pre><code>public class AccessTokenInterceptor extends HandlerInterceptorAdapter
  {    
  @Override
  public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception
  {
      if (handler instanceof HandlerMethod)
      {
          HandlerMethod handlerMethod = (HandlerMethod) handler;
          Authorize authorizeRequired = handlerMethod.getMethodAnnotation(Authorize.class);
          if (authorizeRequired != null)
          {
              String token = request.getHeader("accesstoken");
              ValidateToken(token);
          }
      }
      return true;
  }
  
  protected long ValidateToken(String token)
  {
      AccessToken accessToken = TokenImpl.GetAccessToken(token);
  
      if (accessToken != null)
      {
          if (accessToken.getExpirationDate().compareTo(new Date()) &gt; 0)
          {
              throw new TokenExpiredException();
          }
          return accessToken.getUserId();
      }
      else
      {
          throw new InvalidTokenException();
      }
  }
  </code></pre>
  
  <p>And in my controller, I use @ExceptionHandler to handle exceptions, the code to handle InvalidTokenException looks like</p>
  
  <pre><code>@ExceptionHandler(InvalidTokenException.class)
  public @ResponseBody
  Response handleInvalidTokenException(InvalidTokenException e)
  {
      Log.p.debug(e.getMessage());
      Response rs = new Response();
      rs.setErrorCode(ErrorCode.INVALID_TOKEN);
      return rs;
  }
  </code></pre>
  
  <p>But unfortunately the exception throwed in preHandle method is not caught by the exception handler defined in controller. </p>
  
  <p><strong>Can any one give me an solution of handling the exception?</strong> 
  PS: My controller method produce <strong>both json and xml</strong> using code below:</p>
  
  <pre><code>@RequestMapping(value = "login", method = RequestMethod.POST, produces =
  {
      "application/xml", "application/json"
  })
  </code></pre>