zoukankan      html  css  js  c++  java
  • 将异常堆栈信息转换成字符串

    package cn.com.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限制长度30000,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() > 30000) {
                    result = result.substring(0,30000);
                }
                return result;
            } finally {
                if (null != sw) {
                    try {
                        sw.close();
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    }
                }
                if (null != pw) {
                    pw.close();
                }
            }
        }
    }
  • 相关阅读:
    申请奖励加分
    寒假学习01
    加分项及建议
    12月30日总结
    12月17日 期末总结
    12月31日总结
    12月15日总结
    12月28日总结
    01月03日总结
    01月05日总结
  • 原文地址:https://www.cnblogs.com/bevis-byf/p/11658826.html
Copyright © 2011-2022 走看看