Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.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
Spring 如何在intellij idea中应用@ControllerAdvice?_Spring_Exception_Intellij Idea_Exception Handling_Compiler Errors - Fatal编程技术网

Spring 如何在intellij idea中应用@ControllerAdvice?

Spring 如何在intellij idea中应用@ControllerAdvice?,spring,exception,intellij-idea,exception-handling,compiler-errors,Spring,Exception,Intellij Idea,Exception Handling,Compiler Errors,我与intellij idea合作。 我计划使用@ControllerAdvice来处理异常。 然后intellij报告“未处理的异常”,因为我的代码中没有try-catch块。那怎么解决呢?一定有办法。如果不打算用try-catch处理已检查的异常,则需要在方法签名中重新显示异常。这将强制调用该方法的方法处理异常 public void someMethod() throws IOException { } 注释不能影响语言语义。您可以在运行时使用@ControllerAdvice来处理异

我与intellij idea合作。 我计划使用
@ControllerAdvice
来处理异常。
然后intellij报告“
未处理的异常
”,因为我的代码中没有try-catch块。那怎么解决呢?一定有办法。

如果不打算用try-catch处理已检查的异常,则需要在方法签名中重新显示异常。这将强制调用该方法的方法处理异常

public void someMethod() throws IOException {

}

注释不能影响语言语义。您可以在运行时使用
@ControllerAdvice
来处理异常,但必须声明异常才能让Java编译器接受代码。

我认为您不能在IntelliJ IDEA中忽略它。也许我需要编辑我的问题它可以工作。但是,ExceptionHandler只能捕获控制器层抛出的异常,而服务层抛出的异常永远不会被捕获,无论我的ExceptionHandler在哪里。您应该创建自定义异常(ex-UserServiceException),以便在原始异常发生时在您的服务层中抛出。