Package de.xima.fc.utils
Class XExceptionUtils
- java.lang.Object
-
- de.xima.fc.utils.XExceptionUtils
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
containsExceptionOfType(Throwable e, Class<? extends Throwable> targetType)
Checks if the throwable, any of its causes, or any of its suppressed throwables is of the given target type.static <T extends Throwable>
TconvertThrowableType(Throwable throwable, Function<String,T> wrapperCtor)
Converts the given exception to a different type of exception.static String
getAllFormattedCausesAndSuppressed(Throwable error)
For a given throwable, returns a string with the message of the throwable and the messages from all causes and suppressed throwables of that throwable.
-
-
-
Method Detail
-
containsExceptionOfType
public static boolean containsExceptionOfType(Throwable e, Class<? extends Throwable> targetType)
Checks if the throwable, any of its causes, or any of its suppressed throwables is of the given target type.- Parameters:
e
- Throwable to check.targetType
- Target type to check.- Returns:
- If the exception contains the given target type.
-
convertThrowableType
public static <T extends Throwable> T convertThrowableType(Throwable throwable, Function<String,T> wrapperCtor)
Converts the given exception to a different type of exception. May be useful when you need to ensure an exception is of a specific type, e.g. when you need to transfer exceptions between different JVM (where the target JVM may not have the original exception class).- Type Parameters:
T
- The type of the new exception.- Parameters:
throwable
- The exception to convert.wrapperCtor
- Constructor for the new exception type. The constructor should take a single string argument which is the message of the original exception.- Returns:
- The converted exception.
-
getAllFormattedCausesAndSuppressed
public static String getAllFormattedCausesAndSuppressed(Throwable error)
For a given throwable, returns a string with the message of the throwable and the messages from all causes and suppressed throwables of that throwable. Produces output similar toThrowable.printStackTrace()
, but with only the exception messages and without the call stack entries.- Parameters:
error
- Throwable to process.- Returns:
- The messages of the error and all its causes and suppressions.
-
-