java.lang.Object
dk.cloudcreate.essentials.shared.Exceptions

public final class Exceptions extends Object
  • Constructor Details

    • Exceptions

      public Exceptions()
  • Method Details

    • sneakyThrow

      public static <T extends Throwable, R> R sneakyThrow(Throwable t) throws T
      Allows us to sneaky throw a checked exception without having to wrap it
      Use with caution
      Throws:
      T extends Throwable
    • getStackTrace

      public static String getStackTrace(Throwable throwable)
      Get the stacktrace of the throwable as a String
      Parameters:
      throwable - the exception
      Returns:
      the throwable's full stacktrace
    • getRootCause

      public static Throwable getRootCause(Throwable exception)
      Get the root cause (top most parent) of an Exception.
      Parameters:
      exception - the exception we want the root cause of
      Returns:
      the root cause of the exception - will never be null
    • doesStackTraceContainExceptionOfType

      public static boolean doesStackTraceContainExceptionOfType(Throwable exception, Class<?> exceptionType)
      Check if the stack trace (including causes) contains an exception of a specified type.
      Parameters:
      exception - the root exception
      exceptionType - the type of exception to look for
      Returns:
      true if the exception or one of its causes matches the specified type, false otherwise