Package org.aksw.commons.util.exception
Class ExceptionUtilsAksw
- java.lang.Object
-
- org.aksw.commons.util.exception.ExceptionUtilsAksw
-
public class ExceptionUtilsAksw extends Object
Utils for dealing with typical situtations w.r.t. Exceptions.- Author:
- raven
-
-
Constructor Summary
Constructors Constructor Description ExceptionUtilsAksw()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends Throwable>
voidforwardRootCauseMessageUnless(T t, java.util.function.Consumer<? super String> handler, java.util.function.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, java.util.function.Consumer<? super Throwable> handler, java.util.function.Predicate<? super T>... predicates)static booleanisBrokenPipeException(Throwable t)static booleanisClosedChannelException(Throwable t)static booleanisConnectionRefusedException(Throwable t)static java.util.function.Predicate<Throwable>isRootCauseInstanceOf(Class<?> superClass)static booleanisRootCauseInstanceOf(Throwable t, Class<?> superClass)static booleanisUnknownHostException(Throwable t)static voidrethrowIfNotBrokenPipe(Throwable t)static <T extends Throwable>
voidrethrowUnless(T t, java.util.function.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, java.util.function.Consumer<? super java.util.function.Predicate<? super Throwable>> firstMatchingConditionCallback, java.util.function.Predicate<? super Throwable>... conditions)static voidrethrowUnlessRootCauseMatches(Throwable e, java.util.function.Predicate<? super Throwable>... conditions)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.static Optional<Throwable>unwrap(Throwable given, List<Class<? extends Throwable>> priorities)
-
-
-
Method Detail
-
rethrowUnless
@SafeVarargs public static <T extends Throwable> void rethrowUnless(T t, java.util.function.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
public static boolean isBrokenPipeException(Throwable t)
-
isConnectionRefusedException
public static boolean isConnectionRefusedException(Throwable t)
-
isUnknownHostException
public static boolean isUnknownHostException(Throwable t)
-
isRootCauseInstanceOf
public static java.util.function.Predicate<Throwable> isRootCauseInstanceOf(Class<?> superClass)
-
isRootCauseInstanceOf
public static boolean isRootCauseInstanceOf(Throwable t, Class<?> superClass)
-
rethrowIfNotBrokenPipe
public static void rethrowIfNotBrokenPipe(Throwable t)
-
forwardRootCauseUnless
@SafeVarargs public static <T extends Throwable> void forwardRootCauseUnless(T t, java.util.function.Consumer<? super Throwable> handler, java.util.function.Predicate<? super T>... predicates)
-
forwardRootCauseMessageUnless
@SafeVarargs public static <T extends Throwable> void forwardRootCauseMessageUnless(T t, java.util.function.Consumer<? super String> handler, java.util.function.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
public static Optional<Throwable> unwrap(Throwable given, List<Class<? extends Throwable>> priorities)
-
isClosedChannelException
public static boolean isClosedChannelException(Throwable t)
-
rethrowUnlessRootCauseMatches
@SafeVarargs public static void rethrowUnlessRootCauseMatches(Throwable e, java.util.function.Consumer<? super java.util.function.Predicate<? super Throwable>> firstMatchingConditionCallback, java.util.function.Predicate<? super Throwable>... conditions)
-
rethrowUnlessRootCauseMatches
@SafeVarargs public static void rethrowUnlessRootCauseMatches(Throwable e, java.util.function.Predicate<? super Throwable>... conditions)
-
-