Reputation: 57
i am working with intellij idea.
and i plan to make use of @ControllerAdvice
to handle exceptions.
then intellij reports "unhandled exception
", because i don't have a try-catch block in my code. then how to solve it? there must be a way.
Upvotes: 1
Views: 508
Reputation: 401995
Annotations can not affect language semantics. You may use @ControllerAdvice
to handle exceptions at runtime, but they must be declared for the code to be accepted by the Java compiler.
Upvotes: 0
Reputation: 5813
If you're not going to handle the checked exceptions with a try catch, you'll need to rethrow the exception in the method signature. This will force the method that calls that method to handle the exception
public void someMethod() throws IOException {
}
https://docs.oracle.com/javase/tutorial/essential/exceptions/
Upvotes: 2