Class KiwiRetryerException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- org.kiwiproject.retry.KiwiRetryerException
-
- All Implemented Interfaces:
Serializable
public class KiwiRetryerException extends RuntimeException
Exception thrown byKiwiRetryer.It will wrap either a
RetryExceptionor anInterruptedException.A
RetryExceptionindicates that all attempts failed, while anInterruptedExceptionoccurs 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, aRetryercan be configured with result as well as exception predicates to trigger a retry.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description KiwiRetryerException(String message, Exception cause)Construct an instance with the given information.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Optional<org.kiwiproject.retry.Attempt<?>>getLastAttempt()If the underlying cause is aRetryExceptionreturn the last failedAttempt.OptionalIntgetNumberOfFailedAttempts()If the underlying cause is aRetryExceptionreturn the number of failedAttempts.booleanisCauseInterruptedException()booleanisCauseRetryException()Optional<Throwable>unwrap()Unwrap the givenKiwiRetryerExceptionto reveal the underlying exception that caused it.Optional<org.kiwiproject.retry.RetryException>unwrapAsRetryException()If the underlying cause is aRetryException, unwrap it.Optional<Throwable>unwrapFully()Unwrap the givenKiwiRetryerExceptionto reveal the underlying exception that caused it.static Optional<Throwable>unwrapKiwiRetryerException(KiwiRetryerException kiwiRetryerEx)Unwrap the givenKiwiRetryerExceptionto reveal the underlying exception that caused it.static Optional<Throwable>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 Detail
-
KiwiRetryerException
public KiwiRetryerException(String message, Exception cause)
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 Detail
-
unwrapKiwiRetryerException
public static Optional<Throwable> unwrapKiwiRetryerException(KiwiRetryerException kiwiRetryerEx)
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(KiwiRetryerException)
-
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
public Optional<Throwable> unwrap()
Unwrap the givenKiwiRetryerExceptionto reveal the underlying exception that caused it.- Returns:
- the unwrapped cause
- See Also:
unwrapKiwiRetryerException(KiwiRetryerException),unwrapFully()
-
unwrapFully
public Optional<Throwable> unwrapFully()
Unwrap the givenKiwiRetryerExceptionto reveal the underlying exception that caused it.- Returns:
- the fully unwrapped cause
- See Also:
unwrapKiwiRetryerExceptionFully(KiwiRetryerException)
-
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
public Optional<org.kiwiproject.retry.Attempt<?>> getLastAttempt()
If the underlying cause is aRetryExceptionreturn the last failedAttempt.- Returns:
- an Optional of the last failed Attempt
-
getNumberOfFailedAttempts
public OptionalInt getNumberOfFailedAttempts()
If the underlying cause is aRetryExceptionreturn the number of failedAttempts.- Returns:
- an OptionalInt of the number of failed attempts
-
unwrapAsRetryException
public Optional<org.kiwiproject.retry.RetryException> unwrapAsRetryException()
If the underlying cause is aRetryException, unwrap it.- Returns:
- an Optional of the RetryException causing the retry failure
-
-