Checks to see if this exception or any of its causes
is an instance of the given throwable class

@param ex exception to check
@param exceptionClass class of the exception

@return true if it is
766114
public static boolean causedBy( final Throwable                     ex,
                                    final Class<? extends Throwable>    exceptionClass )
    {
        Throwable    cause = ex;

        while( cause != null && ! exceptionClass.isInstance( cause ) )
        {
            cause = cause.getCause();
        }

        return ( cause == null ) ? false : true;
    }
36115
public boolean isSingleton(String exceptionName) {
        if (size != 1) {
            return false;
        }
        ObjectType e = iterator().next();
        return e.toString().equals(exceptionName);

    }
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);
        }
    }
565913
protected static boolean isRecoverableException(AmazonServiceException ex) {
		if (ex.getErrorType() == null) {
			return false;
		}

		switch (ex.getErrorType()) {
			case Client:
				return ex instanceof ProvisionedThroughputExceededException;
			case Service:
			case Unknown:
				return true;
			default:
				return false;
		}
	}
1225623
public boolean isConnectionError(SQLException ex) {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();

        if (isTraceOn && tc.isEntryEnabled())
            Tr.entry(this, tc, "isConnectionError", ex);

        // Maintain a set in order to check for cycles
        Set<Throwable> chain = new HashSet<Throwable>();

        boolean stale = false;
        for (Throwable t = ex; t != null && !stale && chain.add(t); t = t.getCause()) {
            SQLException sqlX = t instanceof SQLException ? (SQLException) t : null;
            if (isTraceOn && tc.isDebugEnabled())
                Tr.debug(this, tc, "checking " + t,
                         sqlX == null ? null : sqlX.getSQLState(),
                         sqlX == null ? null : sqlX.getErrorCode());
            if (sqlX != null)
                stale |= sqlX instanceof SQLRecoverableException ||
                         sqlX instanceof SQLNonTransientConnectionException ||
                         sqlX instanceof SQLTransientConnectionException && failoverOccurred(sqlX) ||
                         staleErrorCodes.contains(sqlX.getErrorCode()) ||
                         staleSQLStates.contains(sqlX.getSQLState());
        }

        if (isTraceOn && tc.isEntryEnabled())
            Tr.exit(this, tc, "isConnectionError", stale);

        return stale;
    }
748276
public static EvernoteException convert(Exception ex) {
		// construct exception message
		final StringBuilder sb = new StringBuilder();
		sb.append(ex.getClass().getName());
		if (ex instanceof EDAMUserException) {
			final EDAMErrorCode errorCode = ((EDAMUserException) ex).getErrorCode();
			if (errorCode == null) {
				sb.append(", ErrorCode [null");
			} else {
				sb.append(", ErrorCode [" + errorCode + "(" + errorCode.getValue() + ")");
			}
			sb.append("], Parameter [");
			sb.append(((EDAMUserException) ex).getParameter());
			sb.append("]");
		} else if (ex instanceof EDAMSystemException) {
			final EDAMErrorCode errorCode = ((EDAMSystemException) ex).getErrorCode();
			if (errorCode == null) {
				sb.append(", ErrorCode [null");
			} else {
				sb.append(", ErrorCode [" + errorCode + "(" + errorCode.getValue() + ")");
			}
			sb.append("], Message [");
			sb.append(((EDAMSystemException) ex).getMessage());
			sb.append("], RateLimitDuration [");
			sb.append(((EDAMSystemException) ex).getRateLimitDuration());
			sb.append("]");
		} else if (ex instanceof EDAMNotFoundException) {
			sb.append(", Identifier [");
			sb.append(((EDAMNotFoundException) ex).getIdentifier());
			sb.append("], Key [");
			sb.append(((EDAMNotFoundException) ex).getKey());
			sb.append("]");
		} else {
			sb.append(", Message [");
			sb.append(ex.getMessage());
			sb.append("]");
		}
		return new EvernoteException(sb.toString(), ex);
	}
940133
public static boolean isSocketException(Throwable x) { // JENKINS-10524
        if (x == null) {
            return false;
        }
        if (x instanceof SocketException) {
            return true;
        }
        if (String.valueOf(x.getMessage()).equals("Broken pipe")) { // TBD I18N
            return true;
        }
        // JENKINS-20074: various things that Jetty and other components could throw
        if (x instanceof EOFException) {
            return true;
        }
        if (x instanceof IOException && "Closed".equals(x.getMessage())) { // org.eclipse.jetty.server.HttpOutput.print
            return true;
        }
        if (x instanceof IOException && "finished".equals(x.getMessage())) { //com.jcraft.jzlib.DeflaterOutputStream.write
            return true;
        }
        return isSocketException(x.getCause());
    }
331104
static boolean containsInterruptedException(Throwable thrown) {
    if (thrown == null) {
      return false;
    }
    if (thrown instanceof InterruptedException || thrown instanceof InterruptedIOException) {
      return true;
    }
    // tail recurse
    return containsInterruptedException(thrown.getCause());
  }
710309
public static boolean isKnownEOFException (@Nullable final Class <?> aClass)
  {
    if (aClass == null)
      return false;

    final String sClass = aClass.getName ();
    return sClass.equals ("java.io.EOFException") ||
           sClass.equals ("org.mortbay.jetty.EofException") ||
           sClass.equals ("org.eclipse.jetty.io.EofException") ||
           sClass.equals ("org.apache.catalina.connector.ClientAbortException");
  }
3825
@ExceptionHandler(Exception.class)
    public ResponseEntity handleException(Exception ex) {
        EXC_LOGGER.error("[P] Presentation Layer Exception: " + ex.getLocalizedMessage(), ex);
        if (ex instanceof BehaviorAwareException) {
            BehaviorAwareException bae = (BehaviorAwareException) ex;
            return bae.toResponse(bae.getData());
        }
        if (ex instanceof BusinessRuntimeException) {
            BusinessRuntimeException bre = (BusinessRuntimeException) ex;
            return new ResponseEntity<>(Response.newBuilder()
                    .withMessage(bre.getMessage())
                    .withHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR.toString())
                    .withObj(new String[]{bre.getMessageKey()})
                    .build(),
                    HttpStatus.INTERNAL_SERVER_ERROR
            );
        }
        if (ex instanceof HttpBusinessException) {
            HttpBusinessException e = (HttpBusinessException) ex;
            return new ResponseEntity<>(Response.newBuilder()
                    .withMessage(ex.getMessage())
                    .withHttpStatus(e.getHttpStatus().toString())
                    .build(),
                    e.getHttpStatus()
            );
        }
        if (ex instanceof ValidationException) {
            return new ResponseEntity<>(Response.newBuilder()
                    .withMessage(ex.getMessage())
                    .withHttpStatus(HttpStatus.BAD_REQUEST.toString())
                    .build(),
                    HttpStatus.BAD_REQUEST
            );
        }
        if (ex instanceof TechnicalRuntimeException) {
            return new ResponseEntity<>(Response.newBuilder()
                    .withMessage(ex.getMessage())
                    .withHttpStatus(HttpStatus.BAD_GATEWAY.toString())
                    .build(),
                    HttpStatus.BAD_GATEWAY
            );
        }
        return new ResponseEntity<>(Response.newBuilder()
                .withMessage(ex.getMessage())
                .withHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR.toString())
                .build(),
                HttpStatus.INTERNAL_SERVER_ERROR
        );
    }
1286615
@Override
    public boolean canRetry(Throwable exception) {
        if (exception == null) {
            return false;
        }

        Class<? extends Throwable> exceptionClass = exception.getClass();
        if (hasIncludes && !includes.contains(exceptionClass)) {
            return false;
        } else if (hasExcludes && excludes.contains(exceptionClass)) {
            return false;
        } else {
            return this.attemptNumber.incrementAndGet() < (maxAttempts + 1) && ((maxDelay == null) || overallDelay.get() < maxDelay.toMillis());
        }
    }
727509
public static boolean isFromOrSuppressedThrowable(Throwable throwable, Class<? extends Throwable> exceptionClass) {
		return convertFromOrSuppressedThrowable(throwable, exceptionClass, true) != null;
	}
676040
public static boolean isIllegalInstant(Throwable ex) {
        if (ex instanceof IllegalInstantException) {
            return true;
        }
        while (ex.getCause() != null && ex.getCause() != ex) {
            return isIllegalInstant(ex.getCause());
        }
        return false;
    }
533855
private boolean isLogConfigurationMessage(Throwable ex) {
		if (ex instanceof InvocationTargetException) {
			return isLogConfigurationMessage(ex.getCause());
		}
		String message = ex.getMessage();
		if (message != null) {
			for (String candidate : LOG_CONFIGURATION_MESSAGES) {
				if (message.contains(candidate)) {
					return true;
				}
			}
		}
		return false;
	}
880809
public ExceptionHandlerImpl getHandler(Class<? extends Exception> exceptionClass) {
        // If the exception map does not contain the provided exception class, it might
        // still be that a superclass of the exception class is.
        if (!this.exceptionMap.containsKey(exceptionClass)) {

            Class<?> superclass = exceptionClass.getSuperclass();
            do {
                // Is the superclass mapped?
                if (this.exceptionMap.containsKey(superclass)) {
                    // Use the handler for the mapped superclass, and cache handler
                    // for this exception class
                    ExceptionHandlerImpl handler = this.exceptionMap.get(superclass);
                    this.exceptionMap.put(exceptionClass, handler);
                    return handler;
                }

                // Iteratively walk through the exception class's superclasses
                superclass = superclass.getSuperclass();
            } while (superclass != null);

            // No handler found either for the superclasses of the exception class
            // We cache the null value to prevent future
            this.exceptionMap.put(exceptionClass, null);
            return null;
        }

        // Direct map
        return this.exceptionMap.get(exceptionClass);
    }
161797
public static final RuntimeException convertException(Exception ex) {
        if (ex instanceof RuntimeException) {
            return (RuntimeException) ex;
        }
        return new ExceptionConverter(ex);
    }
713653
public ClassDoc exception() {
        ClassDocImpl exceptionClass;
        if (!(holder instanceof ExecutableMemberDoc)) {
            exceptionClass = null;
        } else {
            ExecutableMemberDocImpl emd = (ExecutableMemberDocImpl)holder;
            ClassDocImpl con = (ClassDocImpl)emd.containingClass();
            exceptionClass = (ClassDocImpl)con.findClass(exceptionName);
        }
        return exceptionClass;
    }