我有一些方法會拋出一些異常,我想用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;
}
代碼的AspectJ: -
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中是行不通的。
感謝,這是非常簡單的解決方案。 – 2012-04-28 09:43:50