Recently, I want to use @Exceptionhandler to handle different exceptions, but I found that HttpMediaTypeException and UnsupportedMediaTypeException were not handled by my UnsupportedMediaTypeExceptionHandler, _) 8WWZ~RMFRPDFZ9R%15 8

but caught by my UnexpectedExceptionHandlerHandler R%3_LLD3Q_1@$}V3%L%V62P

Then I found the reason is ExceptionHandlerExceptionResolver.getExceptionHandlerMethod(@Nullable HandlerMethod handlerMethod, Exception exception) when processing, AOO2_@N ~RM0~O ~0S7C}A

it executed in sequence according to the key order of the Map 0B$%88{MVF@O6S$9E%Q7}PR

The UnexpectedExceptionHandlerHandler was catch any exception, and it was in front of the UnsupportedMediaTypeExceptionHandler. That's why it caused such a tragedy, so I want to ask how to make my UnexpectedExceptionHandlerHandler execute finally.

At present, my method is to rename my UnexpectedExceptionHandlerHandler to ZzUnexpectedExceptionHandlerHandler to ensure its final execution😀😀😀

Comment From: RovingSea

If it can't achieve through the existing code, can developers judge the locking type first and then execute the added @ExceptionHandler method?

Comment From: kse-music

you can set order annotation or implements Ordered interface

@Order(0)
public class UnsupportedMediaTypeExceptionHandler {}

Comment From: RovingSea

you can set order annotation or implements Ordered interface

@Order(0) public class UnsupportedMediaTypeExceptionHandler {}

I tried, but it didn't work, and set @Order(Integer.MIN_VALUE)

Comment From: RovingSea

Today, I chose a better method, which is to add @Order(Ordered.HIGHEST_PRECEDENCE) to other ExceptionHandlers. 😅😅