Exception异常转String【转】

把异常的栈轨迹以String形式返回

    /**
     * 把异常的栈轨迹以String形式返回,而不是直接打印到console
     * @author King
     * @time 2015-04-29
     * @return
     */
    public static String getLongInfo(Throwable e){   
        StringWriter sw = new StringWriter();   
        PrintWriter pw = new PrintWriter(sw, true);   
        e.printStackTrace(pw);   
        pw.flush();   
        sw.flush();   
        return sw.toString();   
    } 

  

原文地址:https://www.cnblogs.com/whatlonelytear/p/4919398.html