技术小黑屋

Java Get Full Exception StackTrace

As a coder, I am always handling exceptions or errors,or in a word throwables. To impove the release build, I need to collect every throwable information.
And I need to get the information as string and post it to the Bug Collect Server. Now here is an easy trick to get stacktrace from a Throwable

1
2
3
4
5
6
7
private String getStackTrace(Throwable t) {

    final Writer result = new StringWriter();
    final PrintWriter printWriter = new PrintWriter(result);
    t.printStackTrace(printWriter);
    return result.toString();
}

Others





快来解锁最新版 Typora,新用户券后仅需 84 元!
如何便宜的购买 office 365 ?
新版赤友 NTFS 助手来袭,正版超低价