Class ExceptionUtils


  • public final class ExceptionUtils
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ExceptionUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T extends java.lang.Throwable>
      T
      accumulateException​(T current, T extra)
      Used to "accumulate" exceptions of the same type.
      static java.lang.Throwable peelException​(java.lang.Throwable t)
      Attempts to get to the "effective" exception being thrown, by taking care of some known exceptions that wrap the original thrown one.
      static java.lang.Throwable resolveExceptionCause​(java.lang.Throwable t)  
      static void rethrowAsIoException​(java.lang.Throwable e)  
      static java.lang.RuntimeException toRuntimeException​(java.lang.Throwable t)  
      static java.lang.RuntimeException toRuntimeException​(java.lang.Throwable t, boolean peelThrowable)
      Converts a thrown generic exception to a RuntimeException
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ExceptionUtils

        private ExceptionUtils()
    • Method Detail

      • rethrowAsIoException

        public static void rethrowAsIoException​(java.lang.Throwable e)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • accumulateException

        public static <T extends java.lang.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 java.lang.Throwable resolveExceptionCause​(java.lang.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 java.lang.Throwable peelException​(java.lang.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 java.lang.RuntimeException toRuntimeException​(java.lang.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)
      • toRuntimeException

        public static java.lang.RuntimeException toRuntimeException​(java.lang.Throwable t)