Returns a {@link CounterException} with the throwable.
431250
private static CounterException rethrowAsCounterException(Throwable throwable) {
      //make it public if needed.
      if (throwable instanceof CounterException) {
         return (CounterException) throwable;
      } else if (throwable instanceof ExecutionException || throwable instanceof CompletionException) {
         return rethrowAsCounterException(throwable.getCause());
      } else {
         return new CounterException(throwable);
      }
   }
328253
public Iterator<Throwable> iterator() {

       return new Iterator<Throwable>() {

           SQLException firstException = SQLException.this;
           SQLException nextException = firstException.getNextException();
           Throwable cause = firstException.getCause();

           public boolean hasNext() {
               if(firstException != null || nextException != null || cause != null)
                   return true;
               return false;
           }

           public Throwable next() {
               Throwable throwable = null;
               if(firstException != null){
                   throwable = firstException;
                   firstException = null;
               }
               else if(cause != null){
                   throwable = cause;
                   cause = cause.getCause();
               }
               else if(nextException != null){
                   throwable = nextException;
                   cause = nextException.getCause();
                   nextException = nextException.getNextException();
               }
               else
                   throw new NoSuchElementException();
               return throwable;
           }

           public void remove() {
               throw new UnsupportedOperationException();
           }

       };

    }
768637
private Throwable getCause(Throwable t) {
        Throwable cause = t.getCause();
        if (t.getCause() != null) {
            return cause;
        } else {
            return t;
        }
    }
57442
public boolean ioError(Throwable throwable) {
    if (throwable instanceof IOException || throwable instanceof IOError) {
      return true;
    }
    return throwable.getCause() != null && ioError(throwable.getCause());
  }
425707
public int getStackTraceDepth(Throwable throwable) {
    try {
      return (int) (Integer) getDepthMethod.invoke(javaLangAccess, throwable);
    } catch (InvocationTargetException e) {
      // There really should be no chance of runtime errors.
      if (e.getCause() instanceof RuntimeException) {
        throw (RuntimeException) e.getCause();
      } else if (e.getCause() instanceof Error) {
        throw (Error) e.getCause();
      }
      // This should not be possible because the getStackTraceElement() method does not declare
      // any checked exceptions (though APIs may change over time).
      throw new RuntimeException(e.getCause());
    } catch (IllegalAccessException e) {
      // This should never happen because the method has been successfully invoked once already.
      throw new AssertionError(e);
    }
  }
1310270
public static CounterValue newCounterValue(long currentValue, CounterConfiguration configuration) {
      return configuration.type() == CounterType.BOUNDED_STRONG ?
             newCounterValue(currentValue, configuration.lowerBound(), configuration.upperBound()) :
             newCounterValue(currentValue);
   }
1340583
public static RuntimeException propagate(Throwable throwable) {
    final Throwable t = Preconditions.checkNotNull(throwable, "throwable");
    if (t instanceof Error) {
      throw (Error) t;
    }
    if (t instanceof RuntimeException) {
      throw (RuntimeException) t;
    }

    throw new RuntimeException(t);
  }
463185
@SuppressWarnings("unchecked")
	public static <T extends Throwable> T convertFromOrSuppressedThrowable(Throwable throwable, Class<T> exceptionClass, boolean checkCause) {
		if (throwable == null || exceptionClass == null) {
			return null;
		}
		if (exceptionClass.isAssignableFrom(throwable.getClass())) {
			return (T) throwable;
		}
		if (checkCause) {
			Throwable cause = throwable.getCause();
			if (cause != null && exceptionClass.isAssignableFrom(cause.getClass())) {
				return (T) cause;
			}
		}
		Throwable[] throwables = throwable.getSuppressed();
		if (ArrayUtil.isNotEmpty(throwables)) {
			for (Throwable throwable1 : throwables) {
				if (exceptionClass.isAssignableFrom(throwable1.getClass())) {
					return (T) throwable1;
				}
			}
		}
		return null;
	}
1190304
public static Throwable getCause(Throwable thr) {
		Throwable cause = thr.getCause();
		while (cause != null && cause != thr && cause != cause.getCause() && cause.getCause() != null) {
			cause = cause.getCause();
		}
		return cause == null ? thr : cause;
	}
1323557
public static Status fromThrowable(Throwable t) {
    Throwable cause = checkNotNull(t, "t");
    while (cause != null) {
      if (cause instanceof StatusException) {
        return ((StatusException) cause).getStatus();
      } else if (cause instanceof StatusRuntimeException) {
        return ((StatusRuntimeException) cause).getStatus();
      }
      cause = cause.getCause();
    }
    // Couldn't find a cause with a Status
    return UNKNOWN.withCause(t);
  }
263157
static Throwable cause(Throwable e)
  {
    while (e.getCause() != null
        && (e instanceof InstantiationException
            || e instanceof InvocationTargetException
            || e.getClass().equals(RuntimeExceptionConfig.class))) {
      e = e.getCause();
    }
    
    return e;
  }
1011467
Throwable getExpectedCause(Class expectedExceptionClass, 
			       Throwable exception) {
	Throwable result = exception.getCause();
	if (null != result) {
	    if (!expectedExceptionClass.isAssignableFrom(result.getClass())) {
		result = getExpectedCause(expectedExceptionClass, result);
	    }
	}
	return result;
    }
599644
public static <T> CompletableFuture<T> getFailedFuture(Throwable throwable) {
		CompletableFuture<T> failedAttempt = new CompletableFuture<>();
		failedAttempt.completeExceptionally(throwable);
		return failedAttempt;
	}
530050
public static boolean      isRetryException(Throwable exception)
    {
        if ( exception instanceof KeeperException )
        {
            KeeperException     keeperException = (KeeperException)exception;
            return shouldRetry(keeperException.code().intValue());
        }
        return false;
    }
234807
public static Throwable unwrapForPresentation(Throwable throwable) {
        if (throwable == null) {
            return null;
        }
        while (throwable instanceof ExecutionException || throwable instanceof IllegalStateException
                || throwable.getClass() == RuntimeException.class) {
            // unwrap causes from wrapping exceptions
            final Throwable cause = throwable.getCause();
            if (cause == null) {
                break;
            }
            final String message = throwable.getMessage();
            if (Strings.isNullOrEmpty(message) || cause.toString().equals(message)) {
                // run another iteration
                throwable = cause;
            } else {
                break;
            }
        }
        return throwable;
    }
831963
public static Throwable getConfigException()
  {
    ClassLoader loader = Thread.currentThread().getContextClassLoader();

    for (; loader != null; loader = loader.getParent()) {
      if (loader instanceof EnvironmentClassLoader) {
        EnvironmentClassLoader envLoader = (EnvironmentClassLoader) loader;

        if (envLoader.getConfigException() != null)
          return envLoader.getConfigException();
      }
    }

    return null;
  }
578195
public static <E extends Throwable> @NonNull RuntimeException rethrow(final @NonNull Throwable exception) throws E {
    throw (E) exception;
  }