美文网首页
Java将Exception.printStackTrace()

Java将Exception.printStackTrace()

作者: DongGuangqing | 来源:发表于2017-02-06 19:15 被阅读378次

自己实现

public static String getErrorInfoFromException(Exception e) {
        try {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            return "\r\n" + sw.toString() + "\r\n";
        } catch (Exception e2) {
            return "bad getErrorInfoFromException";
        }
    }

使用apache.commons.lang 包

String str = org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace(Throwable);

相关文章

网友评论

      本文标题:Java将Exception.printStackTrace()

      本文链接:https://www.haomeiwen.com/subject/vipzvttx.html