参考 : https://blog.csdn.net/q649381130/article/details/77182346
import java.io.PrintWriter;
import java.io.StringWriter;
/**
* @Auther: liyue
* @Date: 2020/6/30 17:29
* @Description:
*/
public class ExceptionUtil {
public static String getStackTrace(Throwable throwable) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
try {
throwable.printStackTrace(pw);
return sw.toString();
} finally {
pw.close();
}
}
}