title: Spring @ExceptionHandler does not catch AccessDeniedException
body: <p>I have an exception handler set up with the following code</p>
  
  <pre><code>@ExceptionHandler(Throwable.class)
  public @ResponseBody CustomResponse handleException(Throwable throwable){
      // handles exception, returns a JSON
  }
  </code></pre>
  
  <p>I am using Spring Security 3.1. When I try to do an operation without authentication, the application throws an AccessDeniedException. It never comes to this method. But works fine with other exceptions. Is it the way it is supposed to work?? Or is there something wrong with my code?</p>
  
  <p><a href="https://stackoverflow.com/questions/6742324/exception-handler-in-spring-mvc">This</a> looks like a solution. But it would be better if I can handle exceptions at a single point.</p>
  
  <p>Here is my configuration file</p>
  
  <pre><code>&lt;global-method-security secured-annotations="enabled" pre-post-annotations="enabled" /&gt;
  &lt;http auto-config="true" use-expressions="true"&gt;
      //intercept urls
      &lt;form-login login-page="/signin" default-target-url="/" always-use-default-target="true"/&gt;
  &lt;/http&gt;
  
  &lt;authentication-manager&gt;
      &lt;authentication-provider user-service-ref="userDetailsService"&gt;
          &lt;password-encoder ref="encoder" /&gt;
      &lt;/authentication-provider&gt;
  &lt;/authentication-manager&gt;
  
  &lt;!-- This encoder doesn't require a salt --&gt;
  &lt;beans:bean id="encoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder" /&gt;
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Here the user isn't authenticated (ROLE_ANONYMOUS). When I try to access a protected page, it redirects me to the login URL. My problem here is that, I make an AJAX call. So redirecting to a method that returns ModelAndView doesn't work. Is there a work around here?</p>