Class ThrowableUtils


  • public final class ThrowableUtils
    extends java.lang.Object
    Utility for creating static Throwables.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Throwable catchUnexpected​(java.lang.Throwable delayedCause, java.lang.Throwable cause)
      Used in scenarios where multiple operations which aren't expected to throw but exception propagation must be delayed to preserve control flow.
      static boolean matches​(java.lang.Throwable original, java.lang.Class<? extends java.lang.Throwable> toMatch)
      Finds if the passed original or any of its causes are an instance of toMatch.
      static <T extends java.lang.Throwable>
      T
      unknownStackTrace​(T cause, java.lang.Class<?> clazz, java.lang.String method)
      Set the StackTraceElement for the given Throwable, using the Class and method name.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • unknownStackTrace

        public static <T extends java.lang.Throwable> T unknownStackTrace​(T cause,
                                                                          java.lang.Class<?> clazz,
                                                                          java.lang.String method)
        Set the StackTraceElement for the given Throwable, using the Class and method name.
        Type Parameters:
        T - The type of Throwable.
        Parameters:
        cause - The cause to initialize.
        clazz - The class where the cause is thrown from.
        method - The method where the cause is thrown from.
        Returns:
        cause after the stack trace has been initialized.
      • matches

        public static boolean matches​(java.lang.Throwable original,
                                      java.lang.Class<? extends java.lang.Throwable> toMatch)
        Finds if the passed original or any of its causes are an instance of toMatch.
        Parameters:
        original - Throwable to search.
        toMatch - Throwable to find in original.
        Returns:
        true if passed original or any of its causes are an instance of toMatch.
      • catchUnexpected

        public static java.lang.Throwable catchUnexpected​(@Nullable
                                                          java.lang.Throwable delayedCause,
                                                          java.lang.Throwable cause)
        Used in scenarios where multiple operations which aren't expected to throw but exception propagation must be delayed to preserve control flow.
        Parameters:
        delayedCause - A previously thrown Throwable or null if no previous exception was thrown.
        cause - The newly thrown Throwable.
        Returns:
        The new cause to feed back into this method as delayedCause this method or later throw.