Class ExceptionsHelper

java.lang.Object
org.elasticsearch.ExceptionsHelper

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

    Constructors
    Constructor Description
    ExceptionsHelper()  
  • 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 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)
    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)
    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.
    static java.lang.Throwable unwrapCause​(java.lang.Throwable t)  
    static <T extends java.lang.Throwable>
    java.util.Optional<T>
    unwrapCausesAndSuppressed​(java.lang.Throwable cause, java.util.function.Predicate<java.lang.Throwable> predicate)  
    static java.io.IOException unwrapCorruption​(java.lang.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.
    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 Details

    • ExceptionsHelper

      public ExceptionsHelper()
  • Method Details

    • convertToRuntime

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

      public static ElasticsearchException convertToElastic​(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)
      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 java.lang.Throwable unwrap​(java.lang.Throwable t, java.lang.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
    • reThrowIfNotNull

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

      public static <T extends java.lang.Throwable> java.util.Optional<T> unwrapCausesAndSuppressed​(java.lang.Throwable cause, java.util.function.Predicate<java.lang.Throwable> predicate)
    • maybeError

      public static java.util.Optional<java.lang.Error> maybeError​(java.lang.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​(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) for the semantics.
      Parameters:
      throwable - the throwable to possibly throw on another thread
    • groupBy

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