我有一些引发异常的方法,我想使用 AspectJ 来计算执行时间以及是否引发了一些异常,并登录到错误日志并通过重新引发异常来继续流程。
我试图通过以下方式来实现这一点,但 eclipse 说“未处理的异常类型”。
针对谁使用aspectj的代码:-
public interface Iface {
public void reload() throws TException;
public TUser getUserFromUserId(int userId, String serverId) throws ResumeNotFoundException, TException;
public TUser getUserFromUsername(String username, String serverId) throws ResumeNotFoundException, TException;
public TResume getPartialActiveProfileFromUserId(int userId, int sectionsBitField, String serverId) throws ResumeNotFoundException, UserNotFoundException;
public TResume getPartialActiveProfileFromUsername(String username, int sectionsBitField, String serverId) throws ResumeNotFoundException, UserNotFoundException, TException;
}
代码方面: -
public aspect AspectServerLog {
public static final Logger ERR_LOG = LoggerFactory.getLogger("error");
Object around() : call (* com.abc.Iface.* (..)) {
Object ret;
Throwable ex = null;
StopWatch watch = new Slf4JStopWatch();
try {
ret = proceed();
}catch (UserNotFoundException e) {
ex = e ;
throw e ;
} catch (ResumeNotFoundException e) {
ex = e ;
throw e ;
} catch (Throwable e) {
ex = e ;
throw new RuntimeException(e);
}finally{
watch.stop(thisJoinPoint.toShortString());
if(ex!=null){
StringBuilder mesg = new StringBuilder("Exception in ");
mesg.append(thisJoinPoint.toShortString()).append('(');
for(Object o : thisJoinPoint.getArgs()) {
mesg.append(o).append(',');
}
mesg.append(')');
ERR_LOG.error(mesg.toString(), ex);
numEx++;
}
}
return ret;
}
}
请帮助为什么这个 AspectJ 不起作用。