Class ThrowableUtil

java.lang.Object
org.dellroad.stuff.java.ThrowableUtil

public final class ThrowableUtil extends Object
Utility methods dealing with Throwables.
  • Method Details

    • maskException

      public static <T extends Throwable> T maskException(Throwable t) throws T
      Mask a checked exception and throw it as an unchecked exception.
      Type Parameters:
      T - unchecked exception type
      Parameters:
      t - any exception
      Returns:
      never
      Throws:
      T - always
    • prependCurrentStackTrace

      public static void prependCurrentStackTrace(Throwable t)
      Prepend stack frames from the current thread onto the given exception's stack frames.

      This is used to re-throw an exception created in another thread without losing the stack frame information associated with the current thread.

      Parameters:
      t - exception from another thread
      Throws:
      IllegalArgumentException - if t is null
    • appendStackFrames

      public static StackTraceElement[] appendStackFrames(Throwable t, StackTraceElement[] outerFrames)
      Prepend stack frames from the current thread onto the given exception's stack frames and return the result.
      Parameters:
      t - original exception
      outerFrames - stack frames that should wrap t's stack frames
      Returns:
      an array containing t's stack frames, followed by outerFrames
      Throws:
      IllegalArgumentException - if t or outerFrames is null