I have a class that catches exceptions using the Spring annotation @ExceptionHandler and this class support some custom exceptions as well. I would like that when I raise the exception CustomRuntimeException in this way throw new CustomRuntimeException(args...);, it will be caught and handled in the following method:
@ControllerAdvice
public class CutomExceptionManager {
// code
@ExceptionHandler({CustomRuntimeException.class})
@ResponseBody
private ResponseEntity<ErrorResource> handleCustomException(CustomException e, HttpServletRequest request, HttpServletResponse response) {
logger.error("unhandled exception: ", (Exception)e);
// other code
}
}
This doesn't work.