Determine if a given Throwable is caused by a socket error.
Recursively checks getCause() if outer exception isn't
an instance of the correct class.
@param throwable The Throwable to check.
@return True if the Throwable is a result of a socket error.
549919
public boolean socketError(Throwable throwable) {
    if (throwable instanceof SocketException || throwable instanceof SocketTimeoutException) {
      return true;
    }
    Throwable cause = throwable.getCause();
    // Subset of SSL exceptions that are caused by IO errors (e.g. SSLHandshakeException due to
    // unexpected connection closure) is also a socket error.
    if (throwable instanceof SSLException && cause != null && ioError(cause)) {
      return true;
    }
    return cause != null && socketError(cause);
  }
278340
public static void debug(final Throwable throwable) {
        final StringWriter errors = new StringWriter();
        throwable.printStackTrace(new PrintWriter(errors));
        debugLogger.accept(errors.toString());
    }
20099
private int onException(Exception e) throws IOException {
        eofReached = true;
        if (e instanceof IOException) {
            throw (IOException) e;
        } else if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        } else {
            // Impossible since InputStream throws no other checked exceptions.
            throw Throwables.failure(e);
        }
    }
765232
public static @NonNull Throwable unwrap(final @NonNull Throwable throwable) {
    if(throwable instanceof InvocationTargetException) {
      final /* @Nullable */ Throwable cause = throwable.getCause();
      if(cause != null) {
        return cause;
      }
    }
    return throwable;
  }
876907
@SuppressWarnings("unused")
    private // until I can get this to work
    <T extends Throwable> void rethrowCauseOfType(Class<T> type)
        throws Throwable // this should be throws T
    {
        T cause = causeOfType(type);

        // rethrow acts as if its always throwing Throwable, not the subclass.
        if (cause != null) throw cause;
    }
1188037
public <T extends Throwable> T throwing(T throwable) {
        if (instanceofLAL) {
            ((LocationAwareLogger) logger).log(THROWING_MARKER, FQCN, LocationAwareLogger.ERROR_INT, "throwing", null, throwable);
        }
        return throwable;
    }
917323
private static <E extends Throwable> E wrapIfNecessary(Throwable throwable)
			throws RetryException {
		if (throwable instanceof Error) {
			throw (Error) throwable;
		}
		else if (throwable instanceof Exception) {
			@SuppressWarnings("unchecked")
			E rethrow = (E) throwable;
			return rethrow;
		}
		else {
			throw new RetryException("Exception in retry", throwable);
		}
	}
60134
public static Throwable throwIfIOE(Throwable t) throws IOException {
        if (t instanceof IOException) {
            throw (IOException)t;
        }
        return t;
    }
1268012
public static boolean isCausedBy(final Throwable t, final Class<? extends Throwable>... causeTypes) {
		for (Class<? extends Throwable> type : causeTypes) {
			if (ExceptionUtils.indexOfType(t, type) >= 0) {
				return true;
			}
		}
		return false;
	}
1130205
private final static boolean pstRecursesOnNested(Throwable t) {
        //This method added for D200273

        // the following Throwables don't print out the nested throwable when printStackTrace is called
        Class cName = t.getClass();
        if (cName.getName() != null && cName.getName().equals("org.omg.CORBA.portable.UnknownException"))
            return false;
        if (cName.getName() != null && cName.getName().equals("javax.mail.MessagingException"))
            return false;
        if (t instanceof org.xml.sax.SAXException)
            return false;
        if (cName.getName() != null && cName.getName().equals("javax.servlet.jsp.JspException"))
            return false;
        if (cName.getName() != null && cName.getName().equals("javax.servlet.ServletException"))
            return false;
        if (t instanceof javax.naming.NamingException)
            return false;
        if (t instanceof java.sql.SQLException)
            return false;
        if (cName.getName() != null && cName.getName().equals("javax.jms.JMSException"))
            return false;

        return true;
    }
675985
@Override
    public Throwable getCause() {
        if (exceptions != null && exceptions.size() > 0)
            return (Throwable) exceptions.get(0);
        else
            return null;
    }
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;
    }
9333
public static boolean isFromOrSuppressedThrowable(Throwable throwable, Class<? extends Throwable> exceptionClass, boolean checkCause) {
		return convertFromOrSuppressedThrowable(throwable, exceptionClass, checkCause) != null;
	}
1185353
protected boolean isHostUnavailableException(Throwable throwable, Set<Throwable> path) {
    // Check if the exception is an IOException and check if the
    // message indicates an end of stream on a Connection.
    if ( IOException.class.isInstance(throwable) && throwable.getMessage().contains("unexpected end of stream on") ) {
      return true;
    }
    // we need to check our recursion path to avoid infinite recursion if a
    // getCause() pointed to itself or an ancestor
    if ( throwable.getCause() != null && !path.contains(throwable.getCause()) ) {
      path.add(throwable.getCause());
      boolean isCauseHostUnavailableException = isHostUnavailableException(throwable.getCause(), path);
      if ( isCauseHostUnavailableException == true )
        return true;
    }
    return false;
  }
122491
public boolean causeInstanceOf(Class<? extends Throwable> clazz) {
		Throwable cause = this.getCause();
		if (null != cause && clazz.isInstance(cause)) {
			return true;
		}
		return false;
	}
150188
private static Status getStatus(Throwable throwable) {
    Status status = Status.UNKNOWN;

    if (throwable instanceof StatusRuntimeException) {
      status = ((StatusRuntimeException) throwable).getStatus();
    } else if (throwable instanceof StatusException) {
      status = ((StatusException) throwable).getStatus();
    }
    return status;
  }
183525
public static boolean isClientAbortException(IOException e) {
		
		String exceptionClassName = e.getClass().getName();
		return exceptionClassName.endsWith(".EofException")
				|| exceptionClassName.endsWith(".ClientAbortException");
	}