Class ExceptionsHelper


public final class ExceptionsHelper extends Object
  • Constructor Details

    • ExceptionsHelper

      public ExceptionsHelper()
  • Method Details

    • convertToRuntime

      public static RuntimeException convertToRuntime(Exception e)
    • convertToElastic

      public static ElasticsearchException convertToElastic(Exception e)
    • status

      public static RestStatus status(Throwable t)
    • unwrapCause

      public static Throwable unwrapCause(Throwable t)
    • detailedMessage

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

      public static String stackTrace(Throwable e)
    • formatStackTrace

      public static String formatStackTrace(StackTraceElement[] stackTrace)
    • rethrowAndSuppress

      public static <T extends Throwable> void rethrowAndSuppress(List<T> exceptions) throws T
      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
      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.
      t - Throwable
      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.
      t - Throwable
      clazzes - Classes to look for
      Matching Throwable if one is found, otherwise null
    • reThrowIfNotNull

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

      public static <T extends Throwable> Optional<T> unwrapCausesAndSuppressed(Throwable cause, Predicate<Throwable> predicate)
    • 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.
      cause - the root throwable
      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.
      throwable - the throwable to possibly throw on another thread
    • groupBy

      public static ShardOperationFailedException[] groupBy(ShardOperationFailedException[] failures)
      Deduplicate the failures by exception message and index.