【问题标题】:Regarding Spring AOP Exception Logging关于 Spring AOP 异常日志
【发布时间】:2013-07-02 06:03:42
【问题描述】:

我正在尝试使用 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());

}


DAO 类中的代码,我从中向 Service 抛出异常:

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(..))

我不知道如何获取发生错误的确切行号。请帮忙。

【问题讨论】:

    标签: java spring exception exception-handling spring-aop


    【解决方案1】:

    将原始异常作为原因传递给TrialBalException,然后它将包含原始堆栈跟踪(带有行号)。然后在你的方面打印异常。

    【讨论】:

    • 你能说得详细一点吗?
    猜你喜欢
    • 2018-04-13
    • 1970-01-01
    • 1970-01-01
    • 2017-01-27
    • 2012-09-12
    • 2011-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多