Java Code Examples for org.apache.commons.lang3.exception.ExceptionUtils#indexOfThrowable()
The following examples show how to use
org.apache.commons.lang3.exception.ExceptionUtils#indexOfThrowable() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractCaller.java From sailfish-core with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private <T> T call(Method method, Object... args) throws InterruptedException { try { return (T)method.invoke(this, args); } catch(Exception e) { int interruptedExceptionIndex = ExceptionUtils.indexOfThrowable(e, InterruptedException.class); if(interruptedExceptionIndex != -1) { throw (InterruptedException)ExceptionUtils.getThrowableList(e).get(interruptedExceptionIndex); } else { int knownBugExceptionIndex = ExceptionUtils.indexOfType(e, KnownBugException.class); if (knownBugExceptionIndex != -1) { throw (KnownBugException)ExceptionUtils.getThrowableList(e).get(knownBugExceptionIndex); } else { if(e instanceof InvocationTargetException) { throw new ActionCallException(e.getCause()); } throw new ActionCallException(e); } } } }
Example 2
Source File: WebTimer.java From cuba with Apache License 2.0 | 6 votes |
@Override public void accept(CubaTimer sender) { try { listener.accept(new TimerActionEvent(WebTimer.this)); } catch (RuntimeException e) { int reIdx = ExceptionUtils.indexOfType(e, RemoteException.class); if (reIdx > -1) { RemoteException re = (RemoteException) ExceptionUtils.getThrowableList(e).get(reIdx); for (RemoteException.Cause cause : re.getCauses()) { if (cause.getThrowable() instanceof NoUserSessionException) { log.warn("NoUserSessionException in timer {}, timer will be stopped", id != null ? id : "<noid>"); stop(); return; } } } else if (ExceptionUtils.indexOfThrowable(e, NoUserSessionException.class) > -1) { log.warn("NoUserSessionException in timer {}, timer will be stopped", id != null ? id : "<noid>"); stop(); return; } throw new RuntimeException("Exception on timer action", e); } }
Example 3
Source File: DesktopTimer.java From cuba with Apache License 2.0 | 6 votes |
protected void handleTimerException(RuntimeException ex) { if (ExceptionUtils.indexOfType(ex, java.net.ConnectException.class) > -1) { // If a ConnectException occurred, just log it and ignore log.warn("onTimer error: " + ex.getMessage()); } else { // Otherwise throw the exception, but first search for NoUserSessionException in chain, // if found - stop the timer int reIdx = ExceptionUtils.indexOfType(ex, RemoteException.class); if (reIdx > -1) { RemoteException re = (RemoteException) ExceptionUtils.getThrowableList(ex).get(reIdx); for (RemoteException.Cause cause : re.getCauses()) { //noinspection ThrowableResultOfMethodCallIgnored if (cause.getThrowable() instanceof NoUserSessionException) { log.warn("NoUserSessionException in timer, timer will be stopped"); disposeTimer(); break; } } } else if (ExceptionUtils.indexOfThrowable(ex, NoUserSessionException.class) > -1) { log.warn("NoUserSessionException in timer, timer will be stopped"); disposeTimer(); } throw ex; } }
Example 4
Source File: HerdErrorInformationExceptionHandler.java From herd with Apache License 2.0 | 6 votes |
/** * Handle Activiti exceptions. Note that this method properly handles a null response being passed in. * * @param exception the exception. * @param response the response. * * @return the error information. */ @ExceptionHandler(value = ActivitiException.class) @ResponseBody public ErrorInformation handleActivitiException(Exception exception, HttpServletResponse response) { if ((ExceptionUtils.indexOfThrowable(exception, ActivitiClassLoadingException.class) != -1) || (ExceptionUtils.indexOfType(exception, ELException.class) != -1)) { // These exceptions are caused by invalid workflow configurations (i.e. user error) so they are considered a bad request. return getErrorInformationAndSetStatus(HttpStatus.BAD_REQUEST, exception, response); } else { // For all other exceptions, something is wrong that we weren't expecting so we'll return this as an internal server error and log the error. logError("An Activiti error occurred.", exception); return getErrorInformationAndSetStatus(HttpStatus.INTERNAL_SERVER_ERROR, exception, response); } }
Example 5
Source File: HerdErrorInformationExceptionHandler.java From herd with Apache License 2.0 | 6 votes |
/** * Returns {@code true} if the given throwable is or is not caused by a database constraint violation. * * @param exception - throwable to check. * * @return {@code true} if is constraint violation, {@code false} otherwise. */ private boolean isCausedByConstraintViolationException(Exception exception) { // some databases will throw ConstraintViolationException boolean isConstraintViolation = ExceptionUtils.indexOfThrowable(exception, ConstraintViolationException.class) != -1; // other databases will not throw a nice exception if (!isConstraintViolation) { // We must manually check the error codes Throwable rootThrowable = getRootCause(exception); if (rootThrowable instanceof SQLException) { SQLException sqlException = (SQLException) rootThrowable; if (POSTGRES_SQL_STATE_CODE_FOREIGN_KEY_VIOLATION.equals(sqlException.getSQLState()) || POSTGRES_SQL_STATE_CODE_UNIQUE_INDEX_OR_PRIMARY_KEY_VIOLATION.equals(sqlException.getSQLState())) { isConstraintViolation = true; } } } return isConstraintViolation; }
Example 6
Source File: UpsertSelectOverlappingBatchesIT.java From phoenix with Apache License 2.0 | 6 votes |
@Override public void run() { while (true) { try { runner.call(); } catch (Exception e) { if (ExceptionUtils.indexOfThrowable(e, InterruptedException.class) != -1) { LOGGER.info("Interrupted, exiting", e); Thread.currentThread().interrupt(); return; } LOGGER.error("Hit exception while writing", e); } } }
Example 7
Source File: AbstractCaller.java From sailfish-core with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") public final <T> T call(String utilityName, Object... args) throws UtilityCallException, UtilityNotFoundException, InterruptedException { int maxCompatibilityIndex = -1; Method bestMethod = null; for(Method utilityMethod : utilityMethods.get(utilityName)) { int compatibilityIndex = UtilityManagerUtils.getCompatibilityIndex(utilityMethod, args); if(compatibilityIndex > maxCompatibilityIndex) { maxCompatibilityIndex = compatibilityIndex; bestMethod = utilityMethod; } } if(maxCompatibilityIndex == -1) { throw new UtilityNotFoundException(getSignature(utilityName, args)); } try { return (T)bestMethod.invoke(this, UtilityManagerUtils.getReflectionArgs(bestMethod, args)); } catch(Exception e) { int interruptedExceptionIndex = ExceptionUtils.indexOfThrowable(e, InterruptedException.class); if(interruptedExceptionIndex != -1) { throw (InterruptedException)ExceptionUtils.getThrowableList(e).get(interruptedExceptionIndex); } else { if(e instanceof InvocationTargetException) { throw new UtilityCallException(e.getCause()); } throw new UtilityCallException(e); } } }
Example 8
Source File: AzureClient.java From cloudbreak with Apache License 2.0 | 5 votes |
private <T> T handleAuthException(Supplier<T> function) { try { return function.get(); } catch (RuntimeException e) { if (ExceptionUtils.indexOfThrowable(e, AuthenticationException.class) != -1) { throw new ProviderAuthenticationFailedException(e); } else { throw e; } } }
Example 9
Source File: AzureClient.java From cloudbreak with Apache License 2.0 | 5 votes |
private void handleAuthException(Runnable function) { try { function.run(); } catch (RuntimeException e) { if (ExceptionUtils.indexOfThrowable(e, AuthenticationException.class) != -1) { throw new ProviderAuthenticationFailedException(e); } else { throw e; } } }
Example 10
Source File: TlsEnabledInProcPravegaClusterTest.java From pravega with Apache License 2.0 | 4 votes |
private boolean hasTlsException(Throwable e) { return ExceptionUtils.indexOfThrowable(e, SSLHandshakeException.class) != -1; }