java.lang.Object
dk.cloudcreate.essentials.shared.Exceptions
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleandoesStackTraceContainExceptionOfType(Throwable exception, Class<?> exceptionType) Check if the stack trace (including causes) contains an exception of a specified type.static ThrowablegetRootCause(Throwable exception) Get the root cause (top most parent) of an Exception.static StringgetStackTrace(Throwable throwable) Get the stacktrace of thethrowableas a Stringstatic booleanDetermines whether aThrowable(or anything in its causal chain) represents a critical, unrecoverable error that should not be caught/handled by normal application logic.static <T extends Throwable>
voidrethrowIfCriticalError(T throwable) Rethrows aThrowable(or anything in its causal chain), usingsneakyThrow(Throwable), if the exception represents a critical, unrecoverable error that should not be caught/handled by normal application logic.static <T extends Throwable,R>
RAllows us to sneaky throw a checked exception without having to wrap it
Use with caution
-
Constructor Details
-
Exceptions
public Exceptions()
-
-
Method Details
-
sneakyThrow
Allows us to sneaky throw a checked exception without having to wrap it
Use with caution- Throws:
T extends Throwable
-
getStackTrace
Get the stacktrace of thethrowableas a String- Parameters:
throwable- the exception- Returns:
- the
throwable's full stacktrace
-
getRootCause
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 exceptionexceptionType- the type of exception to look for- Returns:
- true if the exception or one of its causes matches the specified type, false otherwise
-
rethrowIfCriticalError
Rethrows aThrowable(or anything in its causal chain), usingsneakyThrow(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- theThrowableto check- See Also:
-
isCriticalError
Determines whether aThrowable(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- theThrowableto check- Returns:
trueif the throwable (or any suppressed/caused throwable) is considered critical;falseotherwise
-