其他分享
首页 > 其他分享> > 异常输出工具类

异常输出工具类

作者:互联网

public class ExceptionUtil {
    public static String getMessage(Exception e) {
        StringWriter sw = null;
        PrintWriter pw = null;
        try {
            sw = new StringWriter();
            pw = new PrintWriter(sw);
            // 将出错的栈信息输出到printWriter中
            e.printStackTrace(pw);
            pw.flush();
            sw.flush();
        } finally {
            if (sw != null) {
                try {
                    sw.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
            if (pw != null) {
                pw.close();
            }
        }
        return sw.toString();
    }
}

标签:输出,PrintWriter,pw,sw,printStackTrace,flush,工具,null,异常
来源: https://www.cnblogs.com/jqccan/p/16367210.html