> From: David Blevins [mailto:[EMAIL PROTECTED]
> You only need to catch a specific exception type when you
> need to do something unique. The above block could be written as:
>
> try {
> InvocationResult r = getNext().invoke(invocation);
> pool.release(ctx);
> return r;
> } catch (Throwable t) {
> pool.remove(ctx);
> throw t;
> } finally {
> EJBInvocationUtil.putEnterpriseContext(invocation, null);
> }
>
Couple of things :-) :
* this changes the order of release/remove and putEnterpriseContext
not important in this segment, but could be elsewhere - aw, who cares
:-)
* this would require changing invoke from throwing Exception to
Throwable
this might be a good idea anyway
* you also need to catch ApplicationException so it releases rather than
removes
unless perhaps we return an InvocationResult for all 'normal'
invocations
(so it contains the return value or a checked Exception from the user
code)
and then throw any system exception from user-land or any exception
raised
by the container
Hmmm - thinking about it, that last bit seems to make more sense. It
mirrors the distinction between 'normal' completion and a system
exceptions as defined for EJBs; it makes the code for the interceptors
simpler; it allows us to add meta-values to any normal completion and
although we can't add them to system exceptions I don't think that's a
big downside.
So the CallbackInterceptor would then be
try {
Object result = callbackMethod.invoke(instance, callbackArgs);
return new SimpleInvocationResult(result);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause instanceof Exception && !(cause instanceof
RuntimeException)) {
return new SimpleInvocationResult((Exception)cause));
} else {
throw cause;
}
}
and the code David had above would work nicely.
Any objections?
--
Jeremy