[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[aspectj-users] Question about around() advice and exception handling
|
Hello folks,
I was looking in to using AspectJ as a replacement for my current JBossAOP based aspects but I got stumped on a few things.
First was the seeming lack of perJoinPoint type constructs. Which I resolved by making an IdentityHashMap<
JoinPoint.StaticPart,MyState> type cache whenever a new joinpoint was executed. Works basically the same.
Second, I can't seem to figure out how to genericly wrap methods in an around type construct.
In JBossAOP it was as simple as:
@Bind("blah")
public Object adviceMethod(MethodInvocation mi) throws Throwable){
Object ret = null;
Object fault = null;
...do random stuff this advice wants to do...
try{
ret = mi.invokeNext();
}
catch(Throwable th){
fault = th;
}
...do random stuff this advice wants to do...
if (fault) throw fault;
return ret;
}
Problem I have in AspectJ is that it seems I must know the target methods declared checked exceptions. Which isn't really possible.
example:
@Tx
public void foo() {
... foo stuff...
}
@Tx
public void bar() throws Exception{
...bar stuff...
}
There seems to be no construct in AspectJ's language (not the AJ 1.5 annotations, I'm using the traditional aspectj style) to have a catch all / rethrow all type thing.
That or I'm just missing it.
I could make an around() aspect with a:
public around() : execution(@Tx * *(..)) {
boolean failed = true;
try{
proceed();
failed=false;
}
finally{
if (failed) ...do bad thing (rollback / etc) ...
else ...do good thing (commit / etc)...
}
}
but that seems odd, plus I'd lose the ability to see how something fails.
I don't want to use soften since it seems to mask the actual exception thrown which would break virtually all of our code (lots of JDBC / JMS stuff)
It's entirely possible that I'm missing the page with the magic syntax of something like
around() throws *? : execution(@Tx * *(..) throws *?)
Aside from my initial hurdles of syntax/convention converting from JBossAOP to AspectJ, I really like the AspectJ way of doing things.
I look forward to taking our JBossAS restart time from 3min back down to ~2min when this conversion is complete (due to limitations in jbaop's aopc we must use loadtime weaving which adds 1+min to our deploy cycle, which is why I'm trying to switch to AspectJ)