Class ExceptionUtils

java.lang.Object
org.axonframework.common.ExceptionUtils

public final class ExceptionUtils extends Object
Exception utility methods.
Author:
Rene de Waele
  • Method Details

    • findException

      public static Optional<Throwable> findException(Throwable exception, Predicate<Throwable> predicate)
      Checks if the given exception matches the given predicate. If it does an optional with the exception is returned, if not the cause of the exception is checked and returned if matching and so on until a match is found. If neither the given exception nor any of its causes match the predicate an empty Optional is returned.
      Parameters:
      exception - the exception to check
      predicate - the predicate to check the exception and its causes
      Returns:
      an optional containing the exception matching the predicate or an empty optional if neither the given exception nor any of its causes match the predicate
    • findException

      public static <T extends Throwable> Optional<T> findException(Throwable exception, Class<T> exceptionClass)
      Checks if the given exception class is an instance of the given exceptionClass. If so an optional with the exception is returned. If not the cause of the exception is checked and returned if matching and so on until a match is found. If neither the given exception nor any of its causes match the predicate an empty Optional is returned.
      Parameters:
      exception - the exception to check
      exceptionClass - the target exception class
      Returns:
      an optional containing the exception matching the predicate or an empty optional if neither the given exception nor any of its causes match the predicate
    • isExplicitlyNonTransient

      public static boolean isExplicitlyNonTransient(Throwable failure)
      Indicates whether the given failure is clearly non-transient. Non-transient exceptions indicate that the handling of the message will fail in the same way if retried
      Parameters:
      failure - the exception that occurred while processing a message
      Returns:
      true if the exception is clearly non-transient