Class ExceptionsHelper


  • public final class ExceptionsHelper
    extends Object
    • Constructor Detail

      • ExceptionsHelper

        public ExceptionsHelper()
    • Method Detail

      • detailedMessage

        @Deprecated
        public static String detailedMessage​(Throwable t)
        Deprecated.
        Don't swallow exceptions, allow them to propagate.
      • rethrowAndSuppress

        public static <T extends Throwable> void rethrowAndSuppress​(List<T> exceptions)
                                                             throws T extends Throwable
        Rethrows the first exception in the list and adds all remaining to the suppressed list. If the given list is empty no exception is thrown
        Throws:
        T extends Throwable
      • maybeThrowRuntimeAndSuppress

        public static <T extends Throwable> void maybeThrowRuntimeAndSuppress​(List<T> exceptions)
        Throws a runtime exception with all given exceptions added as suppressed. If the given list is empty no exception is thrown
      • useOrSuppress

        public static <T extends Throwable> T useOrSuppress​(T first,
                                                            T second)
      • unwrapCorruption

        public static IOException unwrapCorruption​(Throwable t)
        Looks at the given Throwable's and its cause(s) as well as any suppressed exceptions on the Throwable as well as its causes and returns the first corruption indicating exception (as defined by CORRUPTION_EXCEPTIONS) it finds.
        Parameters:
        t - Throwable
        Returns:
        Corruption indicating exception if one is found, otherwise null
      • unwrap

        public static Throwable unwrap​(Throwable t,
                                       Class<?>... clazzes)
        Looks at the given Throwable and its cause(s) and returns the first Throwable that is of one of the given classes or null if no matching Throwable is found. Unlike unwrapCorruption(java.lang.Throwable) this method does only check the given Throwable and its causes but does not look at any suppressed exceptions.
        Parameters:
        t - Throwable
        clazzes - Classes to look for
        Returns:
        Matching Throwable if one is found, otherwise null
      • isTransportStoppedForAction

        public static boolean isTransportStoppedForAction​(Throwable t,
                                                          String action)
      • reThrowIfNotNull

        public static boolean reThrowIfNotNull​(@Nullable
                                               Throwable e)
        Throws the specified exception. If null if specified then true is returned.
      • maybeError

        public static Optional<Error> maybeError​(Throwable cause)
        Unwrap the specified throwable looking for any suppressed errors or errors as a root cause of the specified throwable.
        Parameters:
        cause - the root throwable
        Returns:
        an optional error if one is found suppressed or a root cause in the tree rooted at the specified throwable
      • maybeDieOnAnotherThread

        public static void maybeDieOnAnotherThread​(Throwable throwable)
        If the specified cause is an unrecoverable error, this method will rethrow the cause on a separate thread so that it can not be caught and bubbles up to the uncaught exception handler. Note that the cause tree is examined for any Error. See maybeError(Throwable) for the semantics.
        Parameters:
        throwable - the throwable to possibly throw on another thread