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 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

      public static boolean isBrokenPipeException(Throwable t)
    • isConnectionRefusedException

      public static boolean isConnectionRefusedException(Throwable t)
    • isUnknownHostException

      public static boolean isUnknownHostException(Throwable t)
    • isRootCauseInstanceOf

      public static 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, 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

      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, Consumer<? super Predicate<? super Throwable>> firstMatchingConditionCallback, Predicate<? super Throwable>... conditions)
    • rethrowUnlessRootCauseMatches

      @SafeVarargs public static void rethrowUnlessRootCauseMatches(Throwable e, Predicate<? super Throwable>... conditions)