获取异常的堆栈信息

import java.io.PrintWriter;
import java.io.StringWriter;

public class ExceptionUtil {

/**
* 获取异常的堆栈信息
*
* @param t
* @return
*/
public static String getStackTrace(Throwable t) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);

try {
t.printStackTrace(pw);
return sw.toString();
} finally {
pw.close();
}
}
}

猜你喜欢

转载自www.cnblogs.com/chinaifae/p/10254337.html