Class Throwables


  • public class Throwables
    extends Object
    Utility class to handle Throwable common methods
    Since:
    3.7.0
    • Method Detail

      • getCauseChain

        public static Iterator<Throwable> getCauseChain​(Throwable throwable)
        Gets a Throwable cause chain as an iterator. The first entry in the iterator will be throwable followed by its cause hierarchy.
        Parameters:
        throwable - the throwable whose cause chain is to determine
        Returns:
        an iterator to navigate in the cause chain
      • getRootCause

        public static Throwable getRootCause​(Throwable throwable)
        Returns the innermost cause of throwable, or throwable itself if it has no cause.
        Parameters:
        throwable - the throwable whose root cause is to determine
        Returns:
        the innermost cause
      • getCauseInChain

        public static Optional<Throwable> getCauseInChain​(Throwable throwable,
                                                          Class<?>... types)
        Returns the most immediate cause in the chain of one of the given types (or sub types).
        Parameters:
        throwable - the throwable whose cause is to determine
        types - the types of cause to look for
        Returns:
        the most immediate cause in the chain of one of the given types (or sub types), empty if none
      • getCauseInChain

        public static <T extends ThrowableOptional<T> getCauseInChain​(Throwable throwable,
                                                                        Class<T> type)
        Returns the most immediate cause in the chain of the given type (or sub type).
        Type Parameters:
        T - the type of cause to look for
        Parameters:
        throwable - the throwable whose cause is to determine
        type - the type of cause to look for
        Returns:
        the most immediate cause in the chain of the given type (or sub type), empty if none