private static Throwable getRootCause(Throwable parent, int depth) {
    if (depth == 0) {
      if (parent == null) {
        throw new IllegalArgumentException("Given parent Throwable is null.");
      }
    }
    Throwable theCause = parent.getCause();
    if (theCause != null) {
      // recurse deeper
      return getRootCause(theCause, depth + 1);
    }

    return parent;
  }
Returns nested 'root' cause of the given parent Throwable. Will return the same Throwable if it
has no 'cause'. If <code>depth</code> is 0, does a <code>null</code> check on the given
<code>parent Throwable</code> & if <code>parent</code> is <code>null</code>, throws
{@link IllegalArgumentException}.

@param parent Throwable whose root cause is to be found
@param depth recurse depth indicator
@return nested root cause.
@throws IllegalArgumentException when parent is <code>null</code> at <code>depth = 0</code>
geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/util/CauseFinder.java