- java.lang.Object
-
- org.tentackle.common.ExceptionHelper
-
public final class ExceptionHelper extends java.lang.ObjectHelper methods dealing with exceptions.- Author:
- harald
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classExceptionHelper.Handler<T extends java.lang.Throwable>Exception handler.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringconcatenateMessages(java.lang.Throwable headOfChain)Concatenates the messages of an exception chain.static java.lang.ThrowableextractException(boolean first, java.lang.Throwable headOfChain, java.lang.Class<? extends java.lang.Throwable>... types)Extracts any of the given exception types from an exception chain.static <T extends java.lang.Throwable>
TextractException(java.lang.Class<T> type, boolean first, java.lang.Throwable headOfChain)Extracts the given exception type from an exception chain.static java.lang.StackTraceElement[]filterStackTrace(java.lang.StackTraceElement[] trace)Filters a given stacktrace skipping all noisy elements without relevant information for the developer.static java.lang.StringgetStackTraceAsString(java.lang.Throwable cause)Returns the stacktrace of a given exception as a string.static booleanhandleException(boolean first, java.lang.Throwable headOfChain, ExceptionHelper.Handler<? extends java.lang.Throwable>... handlers)Extracts any of the given exception types from an exception chain.static booleanisClassValuableForStackTrace(java.lang.String className)Checks if the class is a valuable information within a stracktrace.
-
-
-
Method Detail
-
extractException
public static <T extends java.lang.Throwable> T extractException(java.lang.Class<T> type, boolean first, java.lang.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 if finds the first, else the last in chainheadOfChain- the head of chained exceptions, may be null- Returns:
- the exception, null if none
-
extractException
public static java.lang.Throwable extractException(boolean first, java.lang.Throwable headOfChain, java.lang.Class<? extends java.lang.Throwable>... types)Extracts any of the given exception types from an exception chain.- Parameters:
first- true if finds 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
-
handleException
public static boolean handleException(boolean first, java.lang.Throwable headOfChain, ExceptionHelper.Handler<? extends java.lang.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
public static java.lang.String concatenateMessages(java.lang.Throwable headOfChain)
Concatenates the messages of an exception chain.- Parameters:
headOfChain- the head of chained exceptions, may be null- Returns:
- the message string
-
getStackTraceAsString
public static java.lang.String getStackTraceAsString(java.lang.Throwable cause)
Returns the stacktrace of a given exception as a string.- Parameters:
cause- the exception- Returns:
- the stacktrace as a printable string
-
isClassValuableForStackTrace
public static boolean isClassValuableForStackTrace(java.lang.String className)
Checks if the class is a valuable information within a stracktrace.- Parameters:
className- the classname- Returns:
- true if valuable, else noise
-
filterStackTrace
public static java.lang.StackTraceElement[] filterStackTrace(java.lang.StackTraceElement[] trace)
Filters a given stacktrace skipping all noisy elements without relevant information for the developer.- Parameters:
trace- the stacktrace- Returns:
- the reduced stacktrace
-
-