/** * Get to the base exception (if any). */ public static Throwable baseException(Throwable t) { Throwable wrapped = wrappedException(t); if (wrapped != null) return baseException(wrapped); else return t; }
/** * Get to the base exception (if any). * @param t the Throwable object * @return the base Exception object */ public static Throwable baseException(Throwable t) { Throwable wrapped = wrappedException(t); return wrapped != null? baseException(wrapped) : t; }
/** * Get to the base exception (if any). * @param t the Throwable object * @return the base Exception object */ public static Throwable baseException(Throwable t) { Throwable wrapped = wrappedException(t); return wrapped != null? baseException(wrapped) : t; }
/** * Recursively prints out a stack of wrapped exceptions. */ protected static void printExceptionStack(Throwable th, PrintWriter out, int depth){ //only print the stack depth if the depth is greater than 0 boolean printStackDepth = depth>0; Throwable wrappedException = ExceptionUtil.wrappedException(th); if (wrappedException != null) { printStackDepth = true; printExceptionStack(wrappedException, out, depth + 1); } if(printStackDepth){ out.write("[" + depth + "]"); } th.printStackTrace(out); }
/** * Recursively prints out a stack of wrapped exceptions. * * @param th the Throwable object * @param out the output writer to print to * @param depth the number of levels the stack should be printed */ protected static void printExceptionStack(Throwable th, PrintWriter out, int depth){ //only print the stack depth if the depth is greater than 0 boolean printStackDepth = depth>0; Throwable wrappedException = ExceptionUtil.wrappedException(th); if (wrappedException != null) { printStackDepth = true; printExceptionStack(wrappedException, out, depth + 1); } if(printStackDepth){ out.write("[" + depth + "]"); } th.printStackTrace(out); }
/** * Recursively prints out a stack of wrapped exceptions. * * @param th the Throwable object * @param out the output writer to print to * @param depth the number of levels the stack should be printed */ protected static void printExceptionStack(Throwable th, PrintWriter out, int depth){ //only print the stack depth if the depth is greater than 0 boolean printStackDepth = depth>0; Throwable wrappedException = ExceptionUtil.wrappedException(th); if (wrappedException != null) { printStackDepth = true; printExceptionStack(wrappedException, out, depth + 1); } if(printStackDepth){ out.write("[" + depth + "]"); } th.printStackTrace(out); }
/** * Utility method for converting an exception and all chained root causes into a * string. Unlike <code>exceptionToString(Throwable)</code> which prints the chain * from most nested root cause down to the top-level exception, this method prints * from the top-level exception down to the most nested root cause. * * @param t The throwable exception. * @return The printable exception. */ public static String exceptionFollowedByRootCausesToString(Throwable t) { StringBuffer output = new StringBuffer(); Throwable root = t; while (root != null) { output.append((root == t) ? ((root instanceof Exception) ? " Exception: " : " Error: ") : " Root cause: "); output.append(ExceptionUtil.toString(root)); // Do not recurse if the root cause has already been printed; this will have happened if the root cause has // been assigned to the current Throwable via initCause() or as a constructor argument. Throwable cause = root.getCause(); root = ExceptionUtil.wrappedException(root); if (cause == root) break; } return output.toString(); }
/** * Utility method for converting an exception and all chained root causes into a * string. Unlike <code>exceptionToString(Throwable)</code> which prints the chain * from most nested root cause down to the top-level exception, this method prints * from the top-level exception down to the most nested root cause. * * @param t The throwable exception. * @return The printable exception. */ public static String exceptionFollowedByRootCausesToString(Throwable t) { StringBuffer output = new StringBuffer(); Throwable root = t; while (root != null) { output.append((root == t) ? ((root instanceof Exception) ? " Exception: " : " Error: ") : " Root cause: "); output.append(ExceptionUtil.toString(root)); // Do not recurse if the root cause has already been printed; this will have happened if the root cause has // been assigned to the current Throwable via initCause() or as a constructor argument. Throwable cause = root.getCause(); root = ExceptionUtil.wrappedException(root); if (cause == root) break; } return output.toString(); }
/** * Utility method for converting an exception and all chained root causes into a * string. Unlike <code>exceptionToString(Throwable)</code> which prints the chain * from most nested root cause down to the top-level exception, this method prints * from the top-level exception down to the most nested root cause. * * @param t The throwable exception. * @return The printable exception. */ public static String exceptionFollowedByRootCausesToString(Throwable t) { StringBuffer output = new StringBuffer(); Throwable root = t; while (root != null) { output.append((root == t) ? ((root instanceof Exception) ? " Exception: " : " Error: ") : " Root cause: "); output.append(ExceptionUtil.toString(root)); // Do not recurse if the root cause has already been printed; this will have happened if the root cause has // been assigned to the current Throwable via initCause() or as a constructor argument. Throwable cause = root.getCause(); root = ExceptionUtil.wrappedException(root); if (cause == root) break; } return output.toString(); }