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

瘦欲@ 提交于 2019-12-11 04:56:17

问题


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 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?


回答1:


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.



来源:https://stackoverflow.com/questions/4284031/what-is-the-proper-way-to-deal-with-exceptions-in-interceptors-in-ejb3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!