/** * Utility method for converting an exception into a string. This * method unwinds all wrapped exceptions * @param t The throwable exception * @return The printable exception */ public static String exceptionToString(Throwable t) { StringWriter sw = new StringWriter(); PrintWriter out = new PrintWriter(sw); //print out the exception stack. printExceptionStack(t, out, 0); return sw.toString(); }
/** * Utility method for converting an exception into a string. This * method unwinds all wrapped exceptions * @param t The throwable exception * @return The printable exception */ public static String exceptionToString(Throwable t) { StringWriter sw = new StringWriter(); PrintWriter out = new PrintWriter(sw); //print out the exception stack. printExceptionStack(t, out, 0); return sw.toString(); }
/** * Utility method for converting an exception into a string. This * method unwinds all wrapped exceptions * @param t The throwable exception * @return The printable exception */ public static String exceptionToString(Throwable t) { StringWriter sw = new StringWriter(); PrintWriter out = new PrintWriter(sw); //print out the exception stack. printExceptionStack(t, out, 0); return sw.toString(); }
/** * 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); }