Java 消失异常消息...可能是被抑制的异常?

问题描述 投票:0回答:0

用 Java 编写。这是一个让我很困惑的问题,也是我无法理解的问题。这是 try 块中的一些伪代码和 catch 块中的真实代码。

try {

    // 83 lines of code that do a bunch of stuff, with methods that call other
    // methods which call which call other methods

} catch (Exception e) {
    logger.writeLogError("*********FAILURE BEGIN*********\n");
    e.printStackTrace();
    logger.writeLogError("*********FAILURE END*********\n");
    String errorMesg;

    // Any downstream method that throws an exception without a message
    // will have e.getMessage == null
    if(e.getMessage() == null) {
        // This is for an unanticipated exception.  
        // The stack trace should give more information.
        errorMesg = "Skipped.  Unknown exception.  Check logs for string Exception thrown: ";
    } else {
        errorMesg = "Skipped. " + e.getMessage();
    }
}

变量“errorMesg”被写入数据库表。它不会打印到日志中。所以这就是问题所在。在抛出 NullPointerException 的代码深处某处发生了某些事情。这是我们在日志文件中看到的。

2022-10-25 14:06:28,583 错误 [com.fdc.gibson.services.orderentry.ThisClass] (WorkerThread#39[192.168.136.172:55767]) ********失败开始*** *****

2022-10-25 14:06:28,584 错误 [STDERR] (WorkerThread#39[192.168.136.172:55767]) java.lang.NullPointerException
2022-10-25 14:06:28,584 错误 [com.fdc.gibson.services.orderentry.ThisClass] (WorkerThread#39[192.168.136.172:55767]) *********失败结束**** ****

我不明白为什么堆栈跟踪中的信息如此稀疏。我的猜测是,在深处有一个被抑制的异常,只需添加对 e.getSuppressed() 的调用就会发现这一点。我不知道。但是为什么堆栈跟踪被吞噬了呢?也许这很明显是我想念的。我敢肯定我们在这里做了一些非常愚蠢的事情,但我没有编写大部分代码,我正在努力让它变得愚蠢。

java exception nullpointerexception error-suppression
© www.soinside.com 2019 - 2024. All rights reserved.