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
    • rethrowIfCriticalError

      public static <T extends Throwable> void rethrowIfCriticalError(T throwable)
      Rethrows a Throwable (or anything in its causal chain), using sneakyThrow(Throwable), if the exception represents a critical, unrecoverable error that should not be caught/handled by normal application logic.

      This includes:

      In addition, if such an error appears as a suppressed exception or as the cause of another exception, it is also treated as critical.

      Parameters:
      throwable - the Throwable to check
      See Also:
    • isCriticalError

      public static boolean isCriticalError(Throwable t)
      Determines whether a Throwable (or anything in its causal chain) represents a critical, unrecoverable error that should not be caught/handled by normal application logic.

      This includes:

      In addition, if such an error appears as a suppressed exception or as the cause of another exception, it is also treated as critical.

      Parameters:
      t - the Throwable to check
      Returns:
      true if the throwable (or any suppressed/caused throwable) is considered critical; false otherwise