异常信息输出到log日志里面

package com.bjshenpu.spcloud.dajia.utils;

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

public class ExcrptionUtils {
/* Converts a Throwable object's stack trace to a string.
 * @param t the Throwable object to convert
 * @return a string representation of the stack trace
 */
    public static String printStackTraceToString(Throwable t) {
        StringWriter sw = new StringWriter();
        try (PrintWriter pw = new PrintWriter(sw, true)) {
            t.printStackTrace(pw);
        }
        return sw.toString();
    }

}

猜你喜欢

转载自blog.csdn.net/yz18931904/article/details/131216647