package com.jy.framework.utils;

import cn.hutool.core.io.IoUtil;

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

/**
 * 异常工具类
 */
public class ExceptionUtil {

    /**
     * 获取异常详情字符串
     *
     * @param exception 异常类
     * @return 异常字符串
     */
    public static String getDetailsStr(Exception exception) {
        StringWriter sw = null;
        PrintWriter pw = null;
        try {
            sw = new StringWriter();
            pw = new PrintWriter(sw);
            exception.printStackTrace(pw);
            return sw.toString();
        } finally {
            IoUtil.close(pw);
            IoUtil.close(sw);
        }
    }

}
