Class ExceptionsHelper


  • public final class ExceptionsHelper
    extends java.lang.Object
    • Method Summary

      Modifier and Type Method Description
      static ElasticsearchException convertToElastic​(java.lang.Exception e)  
      static java.lang.RuntimeException convertToRuntime​(java.lang.Exception e)  
      static java.lang.String detailedMessage​(java.lang.Throwable t)
      Deprecated.
      Don't swallow exceptions, allow them to propagate.
      static java.lang.String formatStackTrace​(java.lang.StackTraceElement[] stackTrace)  
      static ShardOperationFailedException[] groupBy​(ShardOperationFailedException[] failures)
      Deduplicate the failures by exception message and index.
      static boolean isTransportStoppedForAction​(java.lang.Throwable t, java.lang.String action)  
      static void maybeDieOnAnotherThread​(java.lang.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.
      static java.util.Optional<java.lang.Error> maybeError​(java.lang.Throwable cause)
      static java.util.Optional<java.lang.Error> maybeError​(java.lang.Throwable cause, org.apache.logging.log4j.Logger logger)
      Unwrap the specified throwable looking for any suppressed errors or errors as a root cause of the specified throwable.
      static <T extends java.lang.Throwable>
      void
      maybeThrowRuntimeAndSuppress​(java.util.List<T> exceptions)
      Throws a runtime exception with all given exceptions added as suppressed.
      static <T extends java.lang.Throwable>
      void
      rethrowAndSuppress​(java.util.List<T> exceptions)
      Rethrows the first exception in the list and adds all remaining to the suppressed list.
      static boolean reThrowIfNotNull​(java.lang.Throwable e)
      Throws the specified exception.
      static java.lang.String stackTrace​(java.lang.Throwable e)  
      static RestStatus status​(java.lang.Throwable t)  
      static java.lang.Throwable unwrap​(java.lang.Throwable t, java.lang.Class<?>... clazzes)  
      static java.lang.Throwable unwrapCause​(java.lang.Throwable t)  
      static java.io.IOException unwrapCorruption​(java.lang.Throwable t)  
      static <T extends java.lang.Throwable>
      T
      useOrSuppress​(T first, T second)  
      • Methods inherited from class java.lang.Object

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

      • ExceptionsHelper

        public ExceptionsHelper()
    • Method Detail

      • convertToRuntime

        public static java.lang.RuntimeException convertToRuntime​(java.lang.Exception e)
      • status

        public static RestStatus status​(java.lang.Throwable t)
      • unwrapCause

        public static java.lang.Throwable unwrapCause​(java.lang.Throwable t)
      • detailedMessage

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

        public static java.lang.String stackTrace​(java.lang.Throwable e)
      • formatStackTrace

        public static java.lang.String formatStackTrace​(java.lang.StackTraceElement[] stackTrace)
      • rethrowAndSuppress

        public static <T extends java.lang.Throwable> void rethrowAndSuppress​(java.util.List<T> exceptions)
                                                                       throws T extends java.lang.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 java.lang.Throwable
      • maybeThrowRuntimeAndSuppress

        public static <T extends java.lang.Throwable> void maybeThrowRuntimeAndSuppress​(java.util.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 java.lang.Throwable> T useOrSuppress​(T first,
                                                                      T second)
      • unwrapCorruption

        public static java.io.IOException unwrapCorruption​(java.lang.Throwable t)
      • unwrap

        public static java.lang.Throwable unwrap​(java.lang.Throwable t,
                                                 java.lang.Class<?>... clazzes)
      • isTransportStoppedForAction

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

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

        public static java.util.Optional<java.lang.Error> maybeError​(java.lang.Throwable cause,
                                                                     org.apache.logging.log4j.Logger logger)
        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
      • maybeError

        public static java.util.Optional<java.lang.Error> maybeError​(java.lang.Throwable cause)
        See maybeError(Throwable, Logger). Uses the class-local logger.
      • maybeDieOnAnotherThread

        public static void maybeDieOnAnotherThread​(java.lang.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, Logger) for the semantics.
        Parameters:
        throwable - the throwable to possibly throw on another thread