package utils;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
/**
* TODO:<p> 异常堆栈信息转换String打印到日志中 <p/>
*
* @package: utils
* @Author mac
* @Date 2020/5/7 8:16 下午
* @Version V1.0
**/
public class ExceptionStackTrace2Str {
public static String getStackTraceString(Exception e) {
StringWriter sw = null;
PrintWriter pw = null;
try {
sw = new StringWriter();
pw = new PrintWriter(sw);
// 将出错的栈信息输出到printWriter中
e.printStackTrace(pw);
pw.flush();
sw.flush();
} finally {
if (sw != null) {
try {
sw.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
if (pw != null) {
pw.close();
}
}
return sw.toString();
}
}