开发者

What is the proper way to deal with Exceptions in Interceptors in EJB3?

I want to use an interceptor for my bean, which will check the validity of a given connection token.

If the connection is invalid, I want to throw a particular exception, if the connection expired, I want to send another (TokenExpiredException, something like this). These Exceptions are included in the interface given to the client.

@AroundInvoke
public 开发者_StackOverflow中文版Object checkParams(InvocationContext ctx) throws TokenExpiredException, Exception{
    //code to check token
    //...
    throw new TokenExpiredException(); 
}

From what I tried, throwing such specific Exception in the Interceptor leads to an UndeclaredThrowableException on the client side. While this exception includes the reference to the cause, it is not really ideal, and can't be dealt with with regular catch clauses.

What is the correct way then to declare different Exception types with Interceptors?


I don't think there is a correct way to do that. Methods should throw only the exceptions they declared, and an interceptor shouldn't add a new one.

My personal case got fixed by adding an error code to our default exception which is thrown by all methods.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜