public final class ExceptionUtil extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
ExceptionUtil.RuntimeExceptionFactory
Interface used by rethrow/peel to wrap the peeled exception
|
| Modifier and Type | Method and Description |
|---|---|
static RuntimeException |
peel(Throwable t) |
static <T extends Throwable> |
peel(Throwable t,
Class<T> allowedType,
String message)
Processes
Throwable t so that the returned Throwable's type matches allowedType or
RuntimeException. |
static <T extends Throwable> |
peel(Throwable t,
Class<T> allowedType,
String message,
ExceptionUtil.RuntimeExceptionFactory runtimeExceptionFactory)
Processes
Throwable t so that the returned Throwable's type matches allowedType or
RuntimeException. |
static RuntimeException |
rethrow(Throwable t) |
static <T extends Throwable> |
rethrow(Throwable t,
Class<T> allowedType) |
static RuntimeException |
rethrow(Throwable t,
ExceptionUtil.RuntimeExceptionFactory runtimeExceptionFactory) |
static <T extends Throwable> |
rethrowAllowedTypeFirst(Throwable t,
Class<T> allowedType)
This rethrow the exception providing an allowed Exception in first priority, even it is a Runtime exception
|
static RuntimeException |
rethrowAllowInterrupted(Throwable t) |
static void |
rethrowIfError(Throwable t) |
static <T extends Throwable> |
sneakyThrow(Throwable t) |
static String |
toString(Throwable cause)
Converts a Throwable stacktrace to a String.
|
static <T> BiConsumer<T,? super Throwable> |
withTryCatch(ILogger logger,
BiConsumer<T,? super Throwable> consumer)
Utility to make sure exceptions inside
CompletionStage.whenComplete(BiConsumer) are not swallowed. |
static <T> BiConsumer<T,? super Throwable> |
withTryCatch(ILogger logger,
String message,
BiConsumer<T,? super Throwable> consumer)
Utility to make sure exceptions inside
CompletionStage.whenComplete(BiConsumer) are not swallowed. |
public static String toString(Throwable cause)
cause - the Throwablepublic static RuntimeException peel(Throwable t)
public static <T extends Throwable> Throwable peel(Throwable t, Class<T> allowedType, String message)
Throwable t so that the returned Throwable's type matches allowedType or
RuntimeException. Processing may include unwrapping t's cause hierarchy, wrapping it in a
HazelcastException or just returning the same instance t if it is already an instance of
RuntimeException.T - expected type of Throwablet - Throwable to be peeledallowedType - the type expected to be returned; when null, this method returns instances
of RuntimeExceptionmessage - if not null, used as the message in the HazelcastException that
may wrap the peeled ThrowableThrowablepublic static <T extends Throwable> Throwable peel(Throwable t, Class<T> allowedType, String message, ExceptionUtil.RuntimeExceptionFactory runtimeExceptionFactory)
Throwable t so that the returned Throwable's type matches allowedType or
RuntimeException. Processing may include unwrapping t's cause hierarchy, wrapping it in a
RuntimeException created by using runtimeExceptionFactory or just returning the same instance t
if it is already an instance of RuntimeException.T - expected type of Throwablet - Throwable to be peeledallowedType - the type expected to be returned; when null, this method returns instances
of RuntimeExceptionmessage - if not null, used as the message in RuntimeException that
may wrap the peeled ThrowableruntimeExceptionFactory - wraps the peeled code using this runtimeExceptionFactoryThrowablepublic static RuntimeException rethrow(Throwable t)
public static RuntimeException rethrow(Throwable t, ExceptionUtil.RuntimeExceptionFactory runtimeExceptionFactory)
public static <T extends Throwable> RuntimeException rethrow(Throwable t, Class<T> allowedType) throws T extends Throwable
T extends Throwablepublic static <T extends Throwable> RuntimeException rethrowAllowedTypeFirst(Throwable t, Class<T> allowedType) throws T extends Throwable
T extends Throwablepublic static void rethrowIfError(Throwable t)
public static RuntimeException rethrowAllowInterrupted(Throwable t) throws InterruptedException
InterruptedException@Nonnull public static <T extends Throwable> RuntimeException sneakyThrow(@Nonnull Throwable t) throws T extends Throwable
T extends Throwable@Nonnull public static <T> BiConsumer<T,? super Throwable> withTryCatch(@Nonnull ILogger logger, @Nonnull BiConsumer<T,? super Throwable> consumer)
CompletionStage.whenComplete(BiConsumer) are not swallowed.
Exceptions will be caught and logged using the supplied logger.@Nonnull public static <T> BiConsumer<T,? super Throwable> withTryCatch(@Nonnull ILogger logger, @Nonnull String message, @Nonnull BiConsumer<T,? super Throwable> consumer)
CompletionStage.whenComplete(BiConsumer) are not swallowed.
Exceptions will be caught and logged using the supplied logger and message.Copyright © 2019 Hazelcast, Inc.. All rights reserved.