Package org.aksw.commons.util.exception
Class ExceptionUtilsAksw
java.lang.Object
org.aksw.commons.util.exception.ExceptionUtilsAksw
Utils for dealing with typical situtations w.r.t. Exceptions.
- Author:
- raven
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Throwable>
voidforwardRootCauseMessageUnless(T t, Consumer<? super String> handler, Predicate<? super T>... predicates) Forward the root cause message of the throwable 't' to 'handler' unless any of the 'predicates' evaluates to true.static <T extends Throwable>
voidforwardRootCauseUnless(T t, Consumer<? super Throwable> handler, Predicate<? super T>... predicates) static booleanstatic booleanstatic booleanisRootCauseInstanceOf(Class<?> superClass) static booleanisRootCauseInstanceOf(Throwable t, Class<?> superClass) static booleanstatic voidstatic <T extends Throwable>
voidrethrowUnless(T t, Predicate<? super T>... predicates) Utility function to rethrow an exception unless a condition is met; in that case it is silently swallowed.static voidrethrowUnlessRootCauseMatches(Throwable e, Consumer<? super Predicate<? super Throwable>> firstMatchingConditionCallback, Predicate<? super Throwable>... conditions) static voidrethrowUnlessRootCauseMatches(Throwable e, Predicate<? super Throwable>... conditions) Check the stack trace for whether it contains an instance of any of the given exceptions classes and return that instance.
-
Constructor Details
-
ExceptionUtilsAksw
public ExceptionUtilsAksw()
-
-
Method Details
-
rethrowUnless
@SafeVarargs public static <T extends Throwable> void rethrowUnless(T t, Predicate<? super T>... predicates) Utility function to rethrow an exception unless a condition is met; in that case it is silently swallowed.rethrowUnless(e, ExceptionUtils::isBrokenPipeException, Foo:isIoException)
- Type Parameters:
T-- Parameters:
t-predicates-
-
isBrokenPipeException
-
isConnectionRefusedException
-
isUnknownHostException
-
isRootCauseInstanceOf
-
isRootCauseInstanceOf
-
rethrowIfNotBrokenPipe
-
forwardRootCauseUnless
@SafeVarargs public static <T extends Throwable> void forwardRootCauseUnless(T t, Consumer<? super Throwable> handler, Predicate<? super T>... predicates) -
forwardRootCauseMessageUnless
@SafeVarargs public static <T extends Throwable> void forwardRootCauseMessageUnless(T t, Consumer<? super String> handler, Predicate<? super T>... predicates) Forward the root cause message of the throwable 't' to 'handler' unless any of the 'predicates' evaluates to true. Useful to e.g. silently suppress broken pipe exceptions in shell scripting pipes. The handler is typically something like logger::warn or logger::error. -
unwrap
@SafeVarargs public static Optional<Throwable> unwrap(Throwable given, Class<? extends Throwable>... priorities) Check the stack trace for whether it contains an instance of any of the given exceptions classes and return that instance. Arguments are checked in order. -
unwrap
-
isClosedChannelException
-
rethrowUnlessRootCauseMatches
-
rethrowUnlessRootCauseMatches
@SafeVarargs public static void rethrowUnlessRootCauseMatches(Throwable e, Predicate<? super Throwable>... conditions)
-