Exceptions { public static List<Throwable> getCausalChain(Throwable t) { Set<Throwable> result = MutableSet.of(); while (t!=null) { if (!result.add(t)) break; t = t.getCause(); } return ImmutableList.copyOf(result); }  static boolean isPrefixBoring(Throwable t); static RuntimeException propagate(Throwable throwable); @Deprecated static RuntimeException propagate(String msg, Throwable throwable); static RuntimeException propagateAnnotateIfWrapping(String msg, Throwable throwable); static RuntimeException propagateAnnotated(String msg, Throwable throwable); static void propagateIfInterrupt(Throwable throwable); static void propagateIfFatal(Throwable throwable); static boolean isFatal(Throwable throwable); static Predicate<Throwable> isFatalPredicate(); @SuppressWarnings("unchecked") static T getFirstThrowableOfType(Throwable from, Class<T> clazz); static Throwable getFirstThrowableMatching(Throwable from, Predicate<? super Throwable> filter); static Throwable getFirstInteresting(Throwable throwable); static Throwable collapse(Throwable source); static Throwable collapseIncludingAllCausalMessages(Throwable source); static Throwable collapse(Throwable source, boolean collapseCausalChain); static List<Throwable> getCausalChain(Throwable t); static boolean isSkippableInContext(Throwable e, Object... contexts); static String collapseText(Throwable t); static String collapseTextInContext(Throwable t, Object ...contexts); static String collapseTextIncludingAllCausalMessages(Throwable t); static RuntimeException propagate(Iterable<? extends Throwable> exceptions); static RuntimeException propagate(String prefix, Iterable<? extends Throwable> exceptions); static Throwable create(Iterable<? extends Throwable> exceptions); static RuntimeException create(@Nullable String prefix, Iterable<? extends Throwable> exceptions); @Beta static boolean isPrefixRequiredForMessageToMakeSense(Throwable t); static String getMessageWithAppropriatePrefix(Throwable t); static boolean isRootBoringClassNotFound(Exception e, String clazz); static final int MAX_COLLAPSE_RECURSIVE_DEPTH; }
@Test public void testGetCausalChain() throws Exception { Exception e1 = new Exception("e1"); Exception e2 = new Exception("e2", e1); assertEquals(Exceptions.getCausalChain(e2), ImmutableList.of(e2, e1)); }
@Test public void testGetCausalChainRecursive() throws Exception { Exception e1 = new Exception("e1") { private static final long serialVersionUID = 1L; public synchronized Throwable getCause() { return this; } }; Exception e2 = new Exception("e2", e1); assertEquals(Exceptions.getCausalChain(e2), ImmutableList.of(e2, e1)); }