Package org.elasticsearch
Class ExceptionsHelper
- java.lang.Object
-
- org.elasticsearch.ExceptionsHelper
-
public final class ExceptionsHelper extends Object
-
-
Constructor Summary
Constructors Constructor Description ExceptionsHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static ElasticsearchExceptionconvertToElastic(Exception e)static RuntimeExceptionconvertToRuntime(Exception e)static StringdetailedMessage(Throwable t)Deprecated.Don't swallow exceptions, allow them to propagate.static StringformatStackTrace(StackTraceElement[] stackTrace)static ShardOperationFailedException[]groupBy(ShardOperationFailedException[] failures)Deduplicate the failures by exception message and index.static booleanisTransportStoppedForAction(Throwable t, String action)static voidmaybeDieOnAnotherThread(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 Optional<Error>maybeError(Throwable cause)Unwrap the specified throwable looking for any suppressed errors or errors as a root cause of the specified throwable.static <T extends Throwable>
voidmaybeThrowRuntimeAndSuppress(List<T> exceptions)Throws a runtime exception with all given exceptions added as suppressed.static <T extends Throwable>
voidrethrowAndSuppress(List<T> exceptions)Rethrows the first exception in the list and adds all remaining to the suppressed list.static booleanreThrowIfNotNull(Throwable e)Throws the specified exception.static StringstackTrace(Throwable e)static RestStatusstatus(Throwable t)static Throwableunwrap(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 ornullif no matching Throwable is found.static ThrowableunwrapCause(Throwable t)static IOExceptionunwrapCorruption(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 byCORRUPTION_EXCEPTIONS) it finds.static <T extends Throwable>
TuseOrSuppress(T first, T second)
-
-
-
Method Detail
-
convertToRuntime
public static RuntimeException convertToRuntime(Exception e)
-
convertToElastic
public static ElasticsearchException convertToElastic(Exception e)
-
status
public static RestStatus status(Throwable t)
-
detailedMessage
@Deprecated public static String detailedMessage(Throwable t)
Deprecated.Don't swallow exceptions, allow them to propagate.
-
formatStackTrace
public static String formatStackTrace(StackTraceElement[] stackTrace)
-
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 byCORRUPTION_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 ornullif no matching Throwable is found. UnlikeunwrapCorruption(java.lang.Throwable)this method does only check the given Throwable and its causes but does not look at any suppressed exceptions.- Parameters:
t- Throwableclazzes- 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 thentrueis 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 anyError. SeemaybeError(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.
-
-