How do you write a full stack trace to the log?

后端 未结 6 1246
感情败类
感情败类 2021-02-18 18:07

I was catching an exception and trying to write the stack trace to the logs like this:

log.warn(e.getMessage());

But all it said was

         


        
6条回答
  •  情话喂你
    2021-02-18 19:08

    In your exception method, the underlying String which contains the message is null.

    The above answer, now struck out, still holds, except that e is not null, but the detailMessage private instance variable on the Throwable class is null, which is why e.getMessage() is the String null, but e.toString() (which calls underlying null detailMessage.toString) throws a NullPointerException.

提交回复
热议问题