Class KiwiRetryerException

  • All Implemented Interfaces:
    Serializable

    public class KiwiRetryerException
    extends RuntimeException
    Exception thrown by 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:
    Serialized Form
    • Method Detail

      • unwrapKiwiRetryerExceptionFully

        public static Optional<Throwable> unwrapKiwiRetryerExceptionFully​(KiwiRetryerException kiwiRetryerEx)
        Unwrap the given KiwiRetryerException to reveal the underlying exception that caused it.

        The difference between unwrapKiwiRetryerException(KiwiRetryerException) and this method and is that the former does not unwrap the RetryException, whereas the latter (this method) does.

        Since it is possible for an attempt to fail without an exception, this method returns an Optional to indicate there might not actually be an exception cause.

        Parameters:
        kiwiRetryerEx - the exception to unwrap
        Returns:
        the fully unwrapped cause
      • 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 a RetryException return the last failed Attempt.
        Returns:
        an Optional of the last failed Attempt
      • getNumberOfFailedAttempts

        public OptionalInt getNumberOfFailedAttempts()
        If the underlying cause is a RetryException return the number of failed Attempts.
        Returns:
        an OptionalInt of the number of failed attempts
      • unwrapAsRetryException

        public Optional<org.kiwiproject.retry.RetryException> unwrapAsRetryException()
        If the underlying cause is a RetryException, unwrap it.
        Returns:
        an Optional of the RetryException causing the retry failure