Class ThrowableUtils


public final class ThrowableUtils extends Object
Utility for creating static Throwables.
  • Method Details

    • unknownStackTrace

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

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

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