Class ErrorKit

java.lang.Object
dev.comfast.errors.ErrorKit

public class ErrorKit extends Object
  • Constructor Details

    • ErrorKit

      public ErrorKit()
  • Method Details

    • _fail

      public static Supplier<RuntimeException> _fail(String errorMsg, Object... msgParams)
      Parameters:
      msgParams - printf params for errorMsg
      Returns:
      Supplier for RuntimeException, fits to Streams/Optionals Usage:

      found = someStream.findFirst().orElseThrow(_fail("Not found '%s'", someParam))

    • rethrow

      public static <T> T rethrow(Supplier<T> getter, String errorMsg, Object... msgParams)
      In case of fail rethrows RuntimeException with additional error message. Usage:

      rethrow(() -> somethingCanFail(), "Something failed");

      rethrow(() -> somethingCanFail(), "Something failed, see: '%s'", "some param");