Class KiwiRetryerException
- All Implemented Interfaces:
Serializable
KiwiRetryer.
It will wrap either a RetryException or an InterruptedException.
A RetryException indicates that all attempts failed, while an InterruptedException occurs when
a thread is interrupted. Note specifically that failed attempts may have failed due to a specific result or
because an exception was thrown. In other words, a Retryer can be configured with result as well as
exception predicates to trigger a retry.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionKiwiRetryerException(String message, Exception cause) Construct an instance with the given information. -
Method Summary
Modifier and TypeMethodDescriptionOptional<org.kiwiproject.retry.Attempt<?>>If the underlying cause is aRetryExceptionreturn the last failedAttempt.If the underlying cause is aRetryExceptionreturn the number of failedAttempts.booleanbooleanunwrap()Unwrap the givenKiwiRetryerExceptionto reveal the underlying exception that caused it.Optional<org.kiwiproject.retry.RetryException>If the underlying cause is aRetryException, unwrap it.Unwrap the givenKiwiRetryerExceptionto reveal the underlying exception that caused it.unwrapKiwiRetryerException(KiwiRetryerException kiwiRetryerEx) Unwrap the givenKiwiRetryerExceptionto reveal the underlying exception that caused it.unwrapKiwiRetryerExceptionFully(KiwiRetryerException kiwiRetryerEx) Unwrap the givenKiwiRetryerExceptionto reveal the underlying exception that caused it.Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
KiwiRetryerException
Construct an instance with the given information.- Parameters:
message- the detail messagecause- the (non-null) cause of the failure (aRetryExceptionorInterruptedException)- Throws:
IllegalArgumentException- if the cause is null, or is not aRetryExceptionorInterruptedException
-
-
Method Details
-
unwrapKiwiRetryerException
Unwrap the givenKiwiRetryerExceptionto reveal the underlying exception that caused it.Since it is possible for an
Attemptto fail without an exception, this method returns anOptionalto indicate there might not actually be an exception cause.- Parameters:
kiwiRetryerEx- the exception to unwrap- Returns:
- the unwrapped cause
- See Also:
-
unwrapKiwiRetryerExceptionFully
public static Optional<Throwable> unwrapKiwiRetryerExceptionFully(KiwiRetryerException kiwiRetryerEx) Unwrap the givenKiwiRetryerExceptionto reveal the underlying exception that caused it.The difference between
unwrapKiwiRetryerException(KiwiRetryerException)and this method and is that the former does not unwrap theRetryException, whereas the latter (this method) does.Since it is possible for an attempt to fail without an exception, this method returns an
Optionalto indicate there might not actually be an exception cause.- Parameters:
kiwiRetryerEx- the exception to unwrap- Returns:
- the fully unwrapped cause
-
unwrap
Unwrap the givenKiwiRetryerExceptionto reveal the underlying exception that caused it.- Returns:
- the unwrapped cause
- See Also:
-
unwrapFully
Unwrap the givenKiwiRetryerExceptionto reveal the underlying exception that caused it.- Returns:
- the fully unwrapped cause
- See Also:
-
isCauseRetryException
public boolean isCauseRetryException()- Returns:
- true if the cause of this exception is a
RetryException, otherwise false
-
isCauseInterruptedException
public boolean isCauseInterruptedException()- Returns:
- true if the cause of this exception is an
InterruptedException, otherwise false
-
getLastAttempt
If the underlying cause is aRetryExceptionreturn the last failedAttempt.- Returns:
- an Optional of the last failed Attempt
-
getNumberOfFailedAttempts
If the underlying cause is aRetryExceptionreturn the number of failedAttempts.- Returns:
- an OptionalInt of the number of failed attempts
-
unwrapAsRetryException
If the underlying cause is aRetryException, unwrap it.- Returns:
- an Optional of the RetryException causing the retry failure
-