Class ExceptionUtils

    • Method Detail

      • accumulateException

        public static <T extends Throwable> T accumulateException​(T current,
                                                                  T extra)
        Used to "accumulate" exceptions of the same type. If the current exception is null then the new one becomes the current, otherwise the new one is added as a suppressed exception to the current one
        Type Parameters:
        T - The exception type
        Parameters:
        current - The current exception
        extra - The extra/new exception
        Returns:
        The resolved exception
        See Also:
        Throwable.addSuppressed(Throwable)
      • resolveExceptionCause

        public static Throwable resolveExceptionCause​(Throwable t)
        Parameters:
        t - The original Throwable - ignored if null
        Returns:
        If Throwable.getCause() is non-null then the cause, otherwise the original exception - null if the original exception was null
      • peelException

        public static Throwable peelException​(Throwable t)
        Attempts to get to the "effective" exception being thrown, by taking care of some known exceptions that wrap the original thrown one.
        Parameters:
        t - The original Throwable - ignored if null
        Returns:
        The effective exception - same as input if not a wrapper
      • toRuntimeException

        public static RuntimeException toRuntimeException​(Throwable t,
                                                          boolean peelThrowable)
        Converts a thrown generic exception to a RuntimeException
        Parameters:
        t - The original thrown exception
        peelThrowable - Whether to determine the root cause by "peeling" any enclosing exceptions
        Returns:
        The thrown cause if already a runtime exception, otherwise a runtime exception of the resolved exception as its cause
        See Also:
        peelException(Throwable)