List of utility methods to do Throwable to String Convert
String | stringify(Throwable t) stringify if (t == null) { return null; StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); t.printStackTrace(pw); return sw.toString(); |
String | getExceptionMessage(Throwable e) get Exception Message String message = e.getMessage(); if (StringUtil.isEmpty(message)) { message = e.getClass().getSimpleName() .replaceFirst("Exception", ""); if (message.length() > LEN) { message = message.substring(0, LEN) + "..."; return message; |
String | getExceptionMessage(Throwable ex) get Exception Message StringBuilder sb = new StringBuilder(ex.getClass().getSimpleName()) .append(":"); if (ex.getMessage() != null) { sb.append(ex.getMessage()).append("\n"); for (StackTraceElement element : ex.getStackTrace()) { sb.append(element.toString()).append("-") .append(element.getLineNumber()).append("\n"); ... |
String | exceptionToString(Throwable t) exception To String if (t == null) return null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { t.printStackTrace(new PrintStream(baos)); } finally { try { baos.close(); ... |
void | failException(String message, Throwable got) Call this if you have an exception you want to fail for! AssertionError ae = new AssertionError(message); if (isandroid.get()) { System.out.println("ANDROID: About to throw AssertionError " + "but we cannot initialize the cause... " + "Here follows both the AssertionError and its cause"); ae.printStackTrace(); System.out.println("And the cause..."); got.printStackTrace(); ... |