Class SuppressExceptions

java.lang.Object
io.github.connellite.util.SuppressExceptions

public class SuppressExceptions extends Object
Runs functional callbacks while swallowing checked and unchecked Exceptions. When a value would be returned, the outcome is null (or the given fallback) if the callback throws or the callback argument is null. Error subclasses are not caught and propagate.
  • Constructor Details

    • SuppressExceptions

      public SuppressExceptions()
  • Method Details

    • run

      public static void run(UncheckedRunnable action)
      Parameters:
      action - ignored if null
    • call

      public static <T> T call(Callable<? extends T> callable)
      Returns:
      callback result, or null if callable is null or throws
    • call

      public static <T> T call(Callable<? extends T> callable, T fallback)
      Returns:
      callback result, or fallback if callable is null or throws
    • get

      public static <T> T get(UncheckedSupplier<? extends T> supplier)
      Returns:
      supplied value, or null if supplier is null or throws
    • get

      public static <T> T get(UncheckedSupplier<? extends T> supplier, T fallback)
      Returns:
      supplied value, or fallback if supplier is null or throws
    • apply

      public static <T, R> R apply(UncheckedFunction<? super T,? extends R> function, T arg)
      Returns:
      function result, or null if function is null or throws
    • apply

      public static <T, R> R apply(UncheckedFunction<? super T,? extends R> function, T arg, R fallback)
      Returns:
      function result, or fallback if function is null or throws
    • apply

      public static <T, U, R> R apply(UncheckedBiFunction<? super T,? super U,? extends R> function, T t, U u)
      Returns:
      function result, or null if function is null or throws
    • apply

      public static <T, U, R> R apply(UncheckedBiFunction<? super T,? super U,? extends R> function, T t, U u, R fallback)
      Returns:
      function result, or fallback if function is null or throws
    • accept

      public static <T> void accept(UncheckedConsumer<? super T> consumer, T arg)
      Parameters:
      consumer - ignored if null
    • accept

      public static <T, U> void accept(UncheckedBiConsumer<? super T,? super U> consumer, T t, U u)
      Parameters:
      consumer - ignored if null
    • test

      public static <T> Boolean test(UncheckedPredicate<? super T> predicate, T arg)
      Returns:
      predicate outcome, or null if predicate is null or throws
    • test

      public static <T> Boolean test(UncheckedPredicate<? super T> predicate, T arg, Boolean fallback)
      Returns:
      predicate outcome, or fallback if predicate is null or throws
    • test

      public static <T, U> Boolean test(UncheckedBiPredicate<? super T,? super U> predicate, T t, U u)
      Returns:
      predicate outcome, or null if predicate is null or throws
    • test

      public static <T, U> Boolean test(UncheckedBiPredicate<? super T,? super U> predicate, T t, U u, Boolean fallback)
      Returns:
      predicate outcome, or fallback if predicate is null or throws