I created a "global" interceptor (below) to simply catch unhandled exceptions
and send the user to a nice error screen. I put it in ejb-jar.xml in front of the Seam
interceptor, since Seam itself is source of Exceptions (no doubt because of my abuse of
the framework).
My concern was by catching Exception and not rethrowing it, I was bypassing the EJB
container's rollback. Sure enough, that's true. That is, the user sees the error
page, but the transaction completes normally.
My question is this: what is a good pattern for this? Should my transactional methods
(save, delete) always catch exceptions, roll back the transaction manually, then rethrow
them so it goes to my error page? Is there a way to send the user to an error page
without bypassing the EJB transaction processing?
BTW, I tried using the new @Interceptor(type=CLIENT) tag to see if I could move my
exception handling outside of the EJB calls. This required removing the entry from
ejb-jar.xml and adding an @Interceptors(MyExceptionInterceptor.class) to the top of my
session bean. Unfortunately, that resulted in the user seeing the Seam debug page, which
is helpful but not pretty. Obviously, I don't fully understand the use of the
@Interceptor tag...
| public class MyExceptionInterceptor {
|
| @AroundInvoke
| public Object handleException(InvocationContext invocation) throws Exception {
|
| try {
| return invocation.proceed();
| }
| catch (Exception t) {
| return "error";
| }
| }
|
| }
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3971412#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...