Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在spring boot中的@ExceptionHandler中引发另一个异常不起作用_Java_Spring Boot_Exception - Fatal编程技术网

Java 在spring boot中的@ExceptionHandler中引发另一个异常不起作用

Java 在spring boot中的@ExceptionHandler中引发另一个异常不起作用,java,spring-boot,exception,Java,Spring Boot,Exception,我有一个CustomException,我用@ExceptionHandler(CustomException.class) 在一种情况下,我将得到一个无效格式异常,因此我需要从那里重新跳转到我的CustomException。我尝试抛出异常,但它没有按预期工作 @ExceptionHandler(InvalidFormatException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) public Error inval

我有一个CustomException,我用
@ExceptionHandler(CustomException.class)

在一种情况下,我将得到一个
无效格式异常
,因此我需要从那里重新跳转到我的CustomException。我尝试抛出异常,但它没有按预期工作

    @ExceptionHandler(InvalidFormatException.class)
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    public Error invalidFormat(InvalidFormatException e) throws CustomException {
      if (logicToValidate()) {
        throw new CustomException();
      } else {
        return new Error(BAD_REQUEST.name(), e.getMessage(), ErrorLevel.ERROR);
      }
    }

    @ExceptionHandler(CustomException.class)
    public Error customException(CustomException e) {
      ...
    }

经过研究,我发现了这条线索。所以现在不可能在spring boot中重新显示异常。相反,如果有的话,我们可以尝试其他的策略