Order of @ExceptionHandler
<p>I use <code>@ControllerAdvice</code> to handle all my app exceptions :</p>

<pre><code>@ControllerAdvice
public class ExceptionHandlingController {

  @ExceptionHandler({UnauthorizedException.class})
  public String unauthorizedException()  {
        .........
  }


  @ExceptionHandler({UnauthorizedAjaxException.class})
  @ResponseBody
  public void unauthorizedAjaxException()  {
        .........
  }

  @ExceptionHandler({Exception.class})
  public String globalException(){
        .........
  }


}
</code></pre>

<p>And somewhere in my code i do <code>throw new UnauthorizedException();</code></p>

<pre><code>   @Around("@annotation(Authenticated)")
   public Object profilingAuthentication(ProceedingJoinPoint pjp) throws Throwable  {

       HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();

       if( request.getSession().getAttribute("idContact") == null ) {
            if( "XMLHttpRequest".equals(request.getHeader("X-Requested-With")) )
                throw new UnauthorizedAjaxException();
            throw new UnauthorizedException();
       } 
       return pjp.proceed();
   }
</code></pre>

<p>But sadly Spring MVC appears to be acting random by using the most generic case (<code>Exception</code>) rather than more specific ones (<code>UnauthorizedException</code> for example). And sometimes he choose the correct one !</p>

<p>How the order works works ? and is there any way to specify the order ?</p>

<p><code>UnauthorizedException</code> is a custom exception</p>

<pre><code>public class UnauthorizedException extends Exception {

    public UnauthorizedException(){
        super();
    }

    public UnauthorizedException(String message){
        super(message);
    }
}
</code></pre>

<p><strong>UPDATE</strong></p>

<p>i found out that the order it's <strong>not rondom</strong> actually the methods who throw <code>UnauthorizedException</code> works normally but the others not !</p>

<pre><code>@Authenticated
@RequestMapping(value="/favoris") 
public String favoris(ModelMap model, HttpServletRequest request) 
      throws UnauthorizedException {
    ....
}

@Authenticated
@RequestMapping(value="/follow") 
public String follow(ModelMap model, HttpServletRequest request) {
    .....
}
</code></pre>

<p>So i have to add <code>throws UnauthorizedException</code> manually or there is some other solution ? </p>