本文共 1138 字,大约阅读时间需要 3 分钟。
import java.util.Map;import org.apache.commons.lang3.StringUtils;import org.apache.commons.lang3.exception.ExceptionUtils;public class ExceptionHelper { public static String getFullStackTrace(Throwable t){ if(t==null)return ""; String expStr = ""; if(t instanceof SystemException){ expStr += getSystemExceptionMsg((SystemException)t); } expStr += StringUtils.join(ExceptionUtils.getRootCauseStackTrace(t),"\n"); return expStr; } private static String getSystemExceptionMsg(SystemException exp) { if(exp==null)return ""; StringBuilder sb = new StringBuilder(); ErrorCode errorCode =exp.getErrorCode(); Mapproperties = exp.getProperties(); if (errorCode != null) { sb.append( errorCode.getCode() + ":"+errorCode.getValue() + ":"+ errorCode + ":" + errorCode.getClass().getName()+"\n" ); } for (String key : properties.keySet()) { sb.append(key + "=[" + properties.get(key) + "]\n"); } return sb.toString(); }}
转载地址:http://gobso.baihongyu.com/