How can I convert a stack trace to a string?

前端 未结 30 1543
再見小時候
再見小時候 2020-11-22 14:51

What is the easiest way to convert the result of Throwable.getStackTrace() to a string that depicts the stacktrace?

30条回答
  •  礼貌的吻别
    2020-11-22 15:27

    private String getCurrentStackTraceString() {
        StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
        return Arrays.stream(stackTrace).map(StackTraceElement::toString)
                .collect(Collectors.joining("\n"));
    }
    

提交回复
热议问题