Class XExceptionUtils


  • public final class XExceptionUtils
    extends Object
    Utility functions for Exceptions and Throwables, in addition to those already provided by ExceptionUtils.
    Since:
    8.0.0
    Author:
    XIMA MEDIA GmbH
    • 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 to Throwable.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.