Skip to content

Can't handle checked exceptions using an interceptor/annotation #44517

Answered by HerrDerb
hydrowoxy asked this question in Q&A
Discussion options

You must be logged in to vote

I don't think this is possible by the way how java works. With AOP or generally interceptors you cannot modify the signature of a method. The given Spring example targets a RestController. You never call those methods directly in the code (the framework does over reflection) that is why the compiler does not complain.

You might want to checkout lomboks @SneakyThrows:https://www.baeldung.com/java-sneaky-throws
But this pretty much rewrites your code with a preprocessor -> https://github.com/projectlombok/lombok/blob/master/src/core/lombok/SneakyThrows.java#L39

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@hydrowoxy
Comment options

Answer selected by hydrowoxy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants