public static String getExceptionStack(Throwable t) { StringBuffer buf = new StringBuffer(); // get exception stack List exceptions = getExceptionsAsList(t); int i = 1; for (Iterator iterator = exceptions.iterator(); iterator.hasNext(); i++) { if (i > exceptionThreshold && exceptionThreshold > 0) { buf.append("(").append(exceptions.size() - i + 1).append(" more...)"); break; } Throwable throwable = (Throwable) iterator.next(); ExceptionReader er = getExceptionReader(throwable); buf.append(i).append(". ").append(er.getMessage(throwable)).append(" ("); buf.append(throwable.getClass().getName()).append(")\n"); if (verbose && throwable.getStackTrace().length > 0) { StackTraceElement e = throwable.getStackTrace()[0]; buf.append(" ") .append(e.getClassName()) .append(":") .append(e.getLineNumber()) .append(" (") .append(getJavaDocUrl(throwable.getClass())) .append(")\n"); } } return buf.toString(); }
/** * Gets an exception reader for the exception * * @param t the exception to get a reader for * @return either a specific reader or an instance of DefaultExceptionReader. This method never * returns null; */ public static ExceptionReader getExceptionReader(Throwable t) { for (ExceptionReader exceptionReader : exceptionReaders) { if (exceptionReader.getExceptionType().isInstance(t)) { return exceptionReader; } } return defaultExceptionReader; }
public static String writeException(Throwable t) { ExceptionReader er = getExceptionReader(t); StringBuffer msg = new StringBuffer(); msg.append(er.getMessage(t)).append(". Type: ").append(t.getClass()); return msg.toString(); }