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(); } } } }
原文地址:https://www.cnblogs.com/bevis-byf/p/11658826.html
时间: 2024-10-07 10:47:56