コード例 #1
0
  public static void appendException(StringBuilder sb, Throwable t, int recurseLimit) {
    if (t != null) {

      sb.append("Exception: ");
      sb.append(t.getClass().getCanonicalName()).append("\r\n");
      sb.append(t.getMessage()).append("\r\n");

      for (StackTraceElement elem : t.getStackTrace()) {
        sb.append("  ").append(elem.toString()).append("\r\n");
      }

      if (recurseLimit > 0 && t.getCause() != null) {
        sb.append("Caused by: ");
        appendException(sb, t.getCause(), recurseLimit - 1);
      }
    }
  }