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();   
    } 

  

posted @ 2015-10-29 09:35  苦涩泪滴  阅读(552)  评论(0编辑  收藏  举报