I'd like to propose the following two methods to ExceptionUtils: 1) getFullStackTrace. This returns a stack-trace including its full print-out of nestables. It assumes that when it hits a nestable, it doesn't need to carry on.
2) isNestedException. [okay, needs to be name changed to isNestedThrowable]. This lets us see if a throwable is nestable, or at least if ExceptionUtils thinks it is. I would be aiming these for the 2.0 release. Any nays? Hen > * A way to get the entire nested stack-trace of an throwable. > * > * @param t The <code>Throwable</code>. > * @return The nested stack trace, with the root cause first. > */ > public static String getFullStackTrace(Throwable t) { > StringWriter sw = new StringWriter(); > PrintWriter pw = new PrintWriter(sw, true); > Throwable[] ts = getThrowables(t); > for(int i=0; i<ts.length; i++) { > ts[i].printStackTrace(pw); > if(isNestedException(ts[i])) { > break; > } > } > return sw.getBuffer().toString(); > } > > /** > * Whether an Throwable is considered nested or not. > * > * @param t The <code>Throwable</code>. > * @return boolean true/false > */ > public static boolean isNestedException(Throwable throwable) { > if(throwable == null) { > return false; > } > > if (throwable instanceof Nestable) { > return true; > } else if (throwable instanceof SQLException) { > return true; > } else if (throwable instanceof InvocationTargetException) { > return true; > } > > int sz = CAUSE_METHOD_NAMES.length; > for(int i=0; i<sz; i++) { > try { > Method method = >throwable.getClass().getMethod(CAUSE_METHOD_NAMES[i], null); > if(method != null) { > return true; > } > } catch (NoSuchMethodException ignored) { > } catch (SecurityException ignored) { > } > } > > try { > Field field = throwable.getClass().getField("detail"); > if(field != null) { > return true; > } > } catch (NoSuchFieldException ignored) { > } catch (SecurityException ignored) { > } > > return false; > } -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>