java.lang.Object
org.tentackle.common.ExceptionHelper
Helper methods dealing with exceptions.
- Author:
- harald
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classExceptionHelper.Handler<T extends Throwable>Exception handler. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringconcatenateMessages(Throwable headOfChain) Concatenates the messages of an exception chain.static ThrowableextractException(boolean first, Throwable headOfChain, Class<? extends Throwable>... types) Extracts any of the given exception types from an exception chain.static <T extends Throwable>
TextractException(Class<T> type, boolean first, Throwable headOfChain) Extracts the given exception type from an exception chain.static TentackleRuntimeExceptionextractTemporaryException(boolean first, Throwable ex) Extracts the first/lastTentackleRuntimeExceptionmarked as temporary in the throwable chain.static StackTraceElement[]filterStackTrace(StackTraceElement[] trace) Filters a given stacktrace skipping all noisy elements without relevant information for the developer.static StringgetMessage(Throwable ex) Determines the first exception in the chain with a valid message.static StringgetStackTraceAsString(Throwable cause) Returns the stacktrace of a given exception as a string.static booleanhandleException(boolean first, Throwable headOfChain, ExceptionHelper.Handler<? extends Throwable>... handlers) Extracts any of the given exception types from an exception chain.static booleanisClassValuableForStackTrace(String className) Checks if the class provides valuable information within a stacktrace.
-
Method Details
-
extractException
public static <T extends Throwable> T extractException(Class<T> type, boolean first, Throwable headOfChain) Extracts the given exception type from an exception chain.- Type Parameters:
T- the exception type to search for- Parameters:
type- the exception class to search forfirst- true to find the first, else the last in chainheadOfChain- the head of chained exceptions, may be null- Returns:
- the exception, null if none
-
extractException
public static Throwable extractException(boolean first, Throwable headOfChain, Class<? extends Throwable>... types) Extracts any of the given exception types from an exception chain.- Parameters:
first- true to find the first, else the last in chainheadOfChain- the head of chained exceptions, may be nulltypes- the exception classes to search for- Returns:
- the exception, null if none
-
extractTemporaryException
Extracts the first/lastTentackleRuntimeExceptionmarked as temporary in the throwable chain.- Parameters:
first- true to find the first, else the last in chainex- the head of chained exceptions, may be null- Returns:
- the temporary exception, null if not found
-
getMessage
Determines the first exception in the chain with a valid message.- Parameters:
ex- the head of chained exceptions, may be null- Returns:
- the message, null if none
-
handleException
public static boolean handleException(boolean first, Throwable headOfChain, ExceptionHelper.Handler<? extends Throwable>... handlers) Extracts any of the given exception types from an exception chain.- Parameters:
first- true if handle the first, else the last in chainheadOfChain- the head of chained exceptions, may be nullhandlers- the exception handlers- Returns:
- true if handled, false if no matching exception found in chain
-
concatenateMessages
Concatenates the messages of an exception chain.- Parameters:
headOfChain- the head of chained exceptions, may be null- Returns:
- the message string
-
getStackTraceAsString
Returns the stacktrace of a given exception as a string.- Parameters:
cause- the exception- Returns:
- the stacktrace as a printable string
-
isClassValuableForStackTrace
Checks if the class provides valuable information within a stacktrace.- Parameters:
className- the classname- Returns:
- true if valuable, else noise
-
filterStackTrace
Filters a given stacktrace skipping all noisy elements without relevant information for the developer.- Parameters:
trace- the stacktrace- Returns:
- the reduced stacktrace
-