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),"
");
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()+"
"
);
}
for (String key : properties.keySet()) {
sb.append(key + "=[" + properties.get(key) + "]
");
}
return sb.toString();
}
}