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();
Map<String,Object> properties = 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();
}
}
转载于:https://www.cnblogs.com/bilaisheng/p/10211008.html
相关资源:JAVA上百实例源码以及开源项目