@Test public void testGetDetailMessageWithCauses() throws Exception { String causeMsg1 = "some cause"; String causeMsg2 = "another cause"; String someMessage = "some message"; Throwable cause2 = new Throwable(causeMsg2); Throwable cause1 = new Throwable(causeMsg1, cause2); Throwable ex = new Throwable(someMessage, cause1); String expected = someMessage + " [Cause: " + causeMsg1 + " [Cause: " + causeMsg2 + "]]"; assertEquals(expected, ExceptionUtil.getDetailMessage(ex)); }
public static String getDetailMessage(Throwable ex) { if (ex == null || Strings.isNullOrEmpty(ex.getMessage())) { return ""; } StringBuilder builder = new StringBuilder(ex.getMessage()); List<Throwable> causes = Lists.newLinkedList(); int counter = 0; Throwable current = ex; while (current.getCause() != null && counter < 10) { Throwable next = current.getCause(); causes.add(next); current = next; counter++; } for (Throwable cause : causes) { if (Strings.isNullOrEmpty(cause.getMessage())) { counter--; continue; } builder.append(" [Cause: ").append(cause.getMessage()); } builder.append(Strings.repeat("]", counter)); return builder.toString(); }
ExceptionUtil { public static String getDetailMessage(Throwable ex) { if (ex == null || Strings.isNullOrEmpty(ex.getMessage())) { return ""; } StringBuilder builder = new StringBuilder(ex.getMessage()); List<Throwable> causes = Lists.newLinkedList(); int counter = 0; Throwable current = ex; while (current.getCause() != null && counter < 10) { Throwable next = current.getCause(); causes.add(next); current = next; counter++; } for (Throwable cause : causes) { if (Strings.isNullOrEmpty(cause.getMessage())) { counter--; continue; } builder.append(" [Cause: ").append(cause.getMessage()); } builder.append(Strings.repeat("]", counter)); return builder.toString(); } }
ExceptionUtil { public static String getDetailMessage(Throwable ex) { if (ex == null || Strings.isNullOrEmpty(ex.getMessage())) { return ""; } StringBuilder builder = new StringBuilder(ex.getMessage()); List<Throwable> causes = Lists.newLinkedList(); int counter = 0; Throwable current = ex; while (current.getCause() != null && counter < 10) { Throwable next = current.getCause(); causes.add(next); current = next; counter++; } for (Throwable cause : causes) { if (Strings.isNullOrEmpty(cause.getMessage())) { counter--; continue; } builder.append(" [Cause: ").append(cause.getMessage()); } builder.append(Strings.repeat("]", counter)); return builder.toString(); }  }
ExceptionUtil { public static String getDetailMessage(Throwable ex) { if (ex == null || Strings.isNullOrEmpty(ex.getMessage())) { return ""; } StringBuilder builder = new StringBuilder(ex.getMessage()); List<Throwable> causes = Lists.newLinkedList(); int counter = 0; Throwable current = ex; while (current.getCause() != null && counter < 10) { Throwable next = current.getCause(); causes.add(next); current = next; counter++; } for (Throwable cause : causes) { if (Strings.isNullOrEmpty(cause.getMessage())) { counter--; continue; } builder.append(" [Cause: ").append(cause.getMessage()); } builder.append(Strings.repeat("]", counter)); return builder.toString(); }  static String getDetailMessage(Throwable ex); }
ExceptionUtil { public static String getDetailMessage(Throwable ex) { if (ex == null || Strings.isNullOrEmpty(ex.getMessage())) { return ""; } StringBuilder builder = new StringBuilder(ex.getMessage()); List<Throwable> causes = Lists.newLinkedList(); int counter = 0; Throwable current = ex; while (current.getCause() != null && counter < 10) { Throwable next = current.getCause(); causes.add(next); current = next; counter++; } for (Throwable cause : causes) { if (Strings.isNullOrEmpty(cause.getMessage())) { counter--; continue; } builder.append(" [Cause: ").append(cause.getMessage()); } builder.append(Strings.repeat("]", counter)); return builder.toString(); }  static String getDetailMessage(Throwable ex);  }