获取异常的堆栈信息

public class ExceptionUtil {

    /**
     * 打印异常的堆栈信息
     */
    public static String getStackTrace(Throwable throwable) {
        try(StringWriter sw = new StringWriter();PrintWriter pw = new PrintWriter(sw)) {
            throwable.printStackTrace(pw);
            return sw.toString();
        } catch (Exception e) {
        }
        return "";
    }
}

 

你可能感兴趣的:(java基础)