src/main/java/com/jmsoftware/datastructuresandalgorithms/common/aspect/ExceptionControllerAdvice.java
/**
     * <p>Exception handler.</p>
     * <p><strong>ATTENTION</strong>: In this method, <strong><em>cannot throw any exception</em></strong>.</p>
     *
     * @param request   HTTP request
     * @param exception any kinds of exception occurred in controller
     * @return custom exception info
     */
Exception handler.
ATTENTION: In this method, cannot throw any exception.

@param request   HTTP request
@param exception any kinds of exception occurred in controller
@return custom exception info
Exception handler . ATTENTION : In this method cannot throw any exception . @param request HTTP request @param exception any kinds of exception occurred in controller @return custom exception info
@ResponseBody
    @ExceptionHandler(value = Exception.class)
    public ResponseBodyBean<Object> handleException(HttpServletRequest request,
                                                    HttpServletResponse response,
                                                    Exception exception) {
        log.error("Exception occurred when [{}] requested access. URL: {}", RequestUtil.getRequestIpAndPort(request),
                  request.getServletPath());
        if (exception instanceof NoHandlerFoundException) {
            log.error("NoHandlerFoundException: Request URL = {}, HTTP method = {}",
                      ((NoHandlerFoundException) exception).getRequestURL(),
                      ((NoHandlerFoundException) exception).getHttpMethod());
            response.setStatus(HttpStatus.NOT_FOUND.getCode());
            return ResponseBodyBean.ofStatus(HttpStatus.NOT_FOUND);
        } else if (exception instanceof HttpRequestMethodNotSupportedException) {
            log.error("Exception occurred when the request handler does not support a specific request method. " +
                      "Current method is {}, Support HTTP method = {}",
                      ((HttpRequestMethodNotSupportedException) exception).getMethod(),
                      ((HttpRequestMethodNotSupportedException) exception).getSupportedHttpMethods());
            response.setStatus(HttpStatus.METHOD_NOT_ALLOWED.getCode());
            return ResponseBodyBean.ofStatus(HttpStatus.METHOD_NOT_ALLOWED);
        } else if (exception instanceof MethodArgumentNotValidException) {
            log.error("Exception occurred when validation on an argument annotated with fails. Exception message: {}",
                      exception.getMessage());
            response.setStatus(HttpStatus.BAD_REQUEST.getCode());
            return ResponseBodyBean.ofStatus(HttpStatus.BAD_REQUEST.getCode(),
                                             getFieldErrorMessageFromException((MethodArgumentNotValidException) exception),
                                             null);
        } else if (exception instanceof ConstraintViolationException) {
            log.error("Constraint violations exception occurred. Exception message: {}", exception.getMessage());
            response.setStatus(HttpStatus.BAD_REQUEST.getCode());
            return ResponseBodyBean.ofStatus(HttpStatus.BAD_REQUEST.getCode(),
                                             CollUtil.getFirst(((ConstraintViolationException) exception).getConstraintViolations()).getMessage(),
                                             null);
        } else if (exception instanceof MethodArgumentTypeMismatchException) {
            log.error("MethodArgumentTypeMismatchException: Parameter name = {}, Exception message: {}",
                      ((MethodArgumentTypeMismatchException) exception).getName(),
                      ((MethodArgumentTypeMismatchException) exception).getMessage());
            response.setStatus(HttpStatus.PARAM_NOT_MATCH.getCode());
            return ResponseBodyBean.ofStatus(HttpStatus.PARAM_NOT_MATCH);
        } else if (exception instanceof HttpMessageNotReadableException) {
            log.error("HttpMessageNotReadableException: {}",
                      ((HttpMessageNotReadableException) exception).getMessage());
            response.setStatus(HttpStatus.PARAM_NOT_NULL.getCode());
            return ResponseBodyBean.ofStatus(HttpStatus.PARAM_NOT_NULL);
        } else if (exception instanceof BaseException) {
            log.error("BaseException: Status code: {}, message: {}, data: {}", ((BaseException) exception).getCode(),
                      exception.getMessage(), ((BaseException) exception).getData());
            response.setStatus(((BaseException) exception).getCode());
            return ResponseBodyBean.ofStatus(((BaseException) exception).getCode(), exception.getMessage(),
                                             ((BaseException) exception).getData());
        } else if (exception instanceof BindException) {
            log.error("Exception message: {} ", exception.getMessage());
            response.setStatus(HttpStatus.INVALID_PARAM.getCode());
            return ResponseBodyBean.ofStatus(HttpStatus.INVALID_PARAM);
        } else if (exception instanceof IllegalArgumentException) {
            log.error("Exception message: {} ", exception.getMessage());
            response.setStatus(HttpStatus.BAD_REQUEST.getCode());
            return ResponseBodyBean.ofStatus(HttpStatus.BAD_REQUEST.getCode(), exception.getMessage(), null);
        }
        log.error("Internal system exception occurred! Exception message: {} ", exception.getMessage(), exception);
        response.setStatus(HttpStatus.ERROR.getCode());
        return ResponseBodyBean.ofStatus(HttpStatus.ERROR.getCode(), HttpStatus.ERROR.getMessage(), null);
    }
@ ResponseBody @ ExceptionHandler ( value = Exception . class ) public ResponseBodyBean < Object > handleException ( HttpServletRequest request , HttpServletResponse response , Exception exception ) { log . error ( "Exception occurred when [{}] requested access. URL: {}" , RequestUtil . getRequestIpAndPort ( request ) , request . getServletPath ( ) ) ; if ( exception instanceof NoHandlerFoundException ) { log . error ( "NoHandlerFoundException: Request URL = {}, HTTP method = {}" , ( ( NoHandlerFoundException ) exception ) . getRequestURL ( ) , ( ( NoHandlerFoundException ) exception ) . getHttpMethod ( ) ) ; response . setStatus ( HttpStatus . NOT_FOUND . getCode ( ) ) ; return ResponseBodyBean . ofStatus ( HttpStatus . NOT_FOUND ) ; } else if ( exception instanceof HttpRequestMethodNotSupportedException ) { log . error ( "Exception occurred when the request handler does not support a specific request method. " + "Current method is {}, Support HTTP method = {}" , ( ( HttpRequestMethodNotSupportedException ) exception ) . getMethod ( ) , ( ( HttpRequestMethodNotSupportedException ) exception ) . getSupportedHttpMethods ( ) ) ; response . setStatus ( HttpStatus . METHOD_NOT_ALLOWED . getCode ( ) ) ; return ResponseBodyBean . ofStatus ( HttpStatus . METHOD_NOT_ALLOWED ) ; } else if ( exception instanceof MethodArgumentNotValidException ) { log . error ( "Exception occurred when validation on an argument annotated with fails. Exception message: {}" , exception . getMessage ( ) ) ; response . setStatus ( HttpStatus . BAD_REQUEST . getCode ( ) ) ; return ResponseBodyBean . ofStatus ( HttpStatus . BAD_REQUEST . getCode ( ) , getFieldErrorMessageFromException ( ( MethodArgumentNotValidException ) exception ) , null ) ; } else if ( exception instanceof ConstraintViolationException ) { log . error ( "Constraint violations exception occurred. Exception message: {}" , exception . getMessage ( ) ) ; response . setStatus ( HttpStatus . BAD_REQUEST . getCode ( ) ) ; return ResponseBodyBean . ofStatus ( HttpStatus . BAD_REQUEST . getCode ( ) , CollUtil . getFirst ( ( ( ConstraintViolationException ) exception ) . getConstraintViolations ( ) ) . getMessage ( ) , null ) ; } else if ( exception instanceof MethodArgumentTypeMismatchException ) { log . error ( "MethodArgumentTypeMismatchException: Parameter name = {}, Exception message: {}" , ( ( MethodArgumentTypeMismatchException ) exception ) . getName ( ) , ( ( MethodArgumentTypeMismatchException ) exception ) . getMessage ( ) ) ; response . setStatus ( HttpStatus . PARAM_NOT_MATCH . getCode ( ) ) ; return ResponseBodyBean . ofStatus ( HttpStatus . PARAM_NOT_MATCH ) ; } else if ( exception instanceof HttpMessageNotReadableException ) { log . error ( "HttpMessageNotReadableException: {}" , ( ( HttpMessageNotReadableException ) exception ) . getMessage ( ) ) ; response . setStatus ( HttpStatus . PARAM_NOT_NULL . getCode ( ) ) ; return ResponseBodyBean . ofStatus ( HttpStatus . PARAM_NOT_NULL ) ; } else if ( exception instanceof BaseException ) { log . error ( "BaseException: Status code: {}, message: {}, data: {}" , ( ( BaseException ) exception ) . getCode ( ) , exception . getMessage ( ) , ( ( BaseException ) exception ) . getData ( ) ) ; response . setStatus ( ( ( BaseException ) exception ) . getCode ( ) ) ; return ResponseBodyBean . ofStatus ( ( ( BaseException ) exception ) . getCode ( ) , exception . getMessage ( ) , ( ( BaseException ) exception ) . getData ( ) ) ; } else if ( exception instanceof BindException ) { log . error ( "Exception message: {} " , exception . getMessage ( ) ) ; response . setStatus ( HttpStatus . INVALID_PARAM . getCode ( ) ) ; return ResponseBodyBean . ofStatus ( HttpStatus . INVALID_PARAM ) ; } else if ( exception instanceof IllegalArgumentException ) { log . error ( "Exception message: {} " , exception . getMessage ( ) ) ; response . setStatus ( HttpStatus . BAD_REQUEST . getCode ( ) ) ; return ResponseBodyBean . ofStatus ( HttpStatus . BAD_REQUEST . getCode ( ) , exception . getMessage ( ) , null ) ; } log . error ( "Internal system exception occurred! Exception message: {} " , exception . getMessage ( ) , exception ) ; response . setStatus ( HttpStatus . ERROR . getCode ( ) ) ; return ResponseBodyBean . ofStatus ( HttpStatus . ERROR . getCode ( ) , HttpStatus . ERROR . getMessage ( ) , null ) ; }
<p>Exception handler.</p>
 <p><strong>ATTENTION</strong>: In this method, <strong><em>cannot throw any exception</em></strong>.</p>
<p > Exception handler . < / p > <p > <strong > ATTENTION< / strong > : In this method <strong > <em > cannot throw any exception< / em > < / strong > . < / p >
// FIXME: THIS IS NOT A PROBLEM //  ATTENTION: Use only ResponseBodyBean.ofStatus() in handleException() method and DON'T throw any exception