码迷,mamicode.com
首页 > 其他好文 > 详细

将异常堆栈信息转换成字符串

时间:2019-10-12 11:14:12      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:ons   apach   style   ext   sgu   mysql   防止   string   substr   

package cn.com.aia.grouplife.utils;

import org.apache.commons.lang3.StringUtils;

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

public class ExceptionMsgUtils {

    /**
     * getExceptionInfo
     * @param e
     * @return result限制长度65530,MySQL text字段长65535,防止存不进去
     */
    public static String getExceptionInfo(Exception e) {
        StringWriter sw = null;
        PrintWriter pw = null;
        try {
            sw = new StringWriter();
            pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            String result = sw.toString();
            if(StringUtils.isNotBlank(result) && result.length() > 65530) {
                result = result.substring(0,65530);
            }
            return result;
        } finally {
            if (null != sw) {
                try {
                    sw.close();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
            if (null != pw) {
                pw.close();
            }
        }
    }
}

 

将异常堆栈信息转换成字符串

标签:ons   apach   style   ext   sgu   mysql   防止   string   substr   

原文地址:https://www.cnblogs.com/bevis-byf/p/11658826.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!