Exception异常转String【转】

时间:2021-06-25 16:52:21

把异常的栈轨迹以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();
}