import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
/**
* @author ParanoidCAT
*/
public class ExceptionUtils {
private ExceptionUtils() throws Exception {
throw new Exception("no ExceptionUtils instance should be created");
}
/**
* 获取异常的堆栈信息
*
* @param throwable 异常
* @return 堆栈信息文本
*/
public static String getStackTrace(Throwable throwable) {
try (StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter, true)) {
throwable.printStackTrace(printWriter);
return stringWriter.getBuffer().toString();
} catch (IOException e) {
return "";
}
}
}