简体   繁体   中英

Throwing custom exception inside Enum but flow is not coming to @ExceptionHandler method

    public enum Metadata{
        AC, CD;
@jsonCreator
public static Metadata get(String value) throw customException
if(!isValid(value)){
throw customException();
}
    }

My handler method

@ExceptionHandler(customException.class)
public ResponseEntity<Response> handeljsonError(customException e){
return response;
}

when custom exception is thrown from Enum metadata so flow is not coming on custom handler instead of that it is going to httpMessageNonReadableException which is other override method so when I debug its cause its shows ValueInstantiationException.

I want my custom exception method should get run instead of httpMessageNonReadableException

The class should extend the ResponseEntityExceptionHandler with @ControllerAdvice annotation.

@ControllerAdvice
public class ControllerAdvisor extends ResponseEntityExceptionHandler 

ResponseEntityExceptionHandler is called by spring only in HTTP flow, make sure your code is in the scope of HTTP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM