我正在尝试使用 Spring AOP 获取发生异常的确切行。
AspectLogger.java 中的代码:
@AfterThrowing(pointcut = "execution(* com.ing.trialbal.*.*.*(..))", throwing = "ex")
public void afterThrowingAdvice(JoinPoint jp, TrialBalException ex) {
logger.info("Exception : After throwing " + jp.getSignature().getName()
+ "()");
logger.info("********* " + ex.getMessage()
+ " Exception occured during " + jp.toShortString());
System.out.println("********* " + ex.getMessage()
+ " Exception occured during " + jp.toShortString());
}
我向 Service 抛出异常的 DAO 类中的代码:
try {
...
} catch (Exception e) {
System.out.println("(((((((((((((" + e.getStackTrace().toString());
throw new TrialBalException("Error.TrialBalance.Exception : " + e);
} finally {
try {
pStmt.close();
} catch (Exception e) {
e.printStackTrace();
}
}
在日志中我得到:
异常:在抛出 getLongTBDetail()
Error.TrialBalance.Exception : java.lang.NullPointerException 执行期间发生异常(LongTBDaoImpl.getLongTBDetail(..))
我不知道如何获得发生错误的确切行号。请帮忙。