Class TryWithResult<O>

  • All Implemented Interfaces:
    Catchable

    @NullMarked
    public class TryWithResult<O>
    extends AbstractLoggable
    implements Catchable
    A try/catch chain with an expected result
    Since:
    0.2
    • Method Detail

      • andTryWithResult

        public <T> TryWithResult<T> andTryWithResult​(java.util.function.Function<O,​T> function)
        Try another function and update result or resend exception.
        Type Parameters:
        T - The expected return type
        Parameters:
        function - The function to be executed
        Returns:
        TryWithResult for further processing
      • andTry

        public Try andTry​(java.util.function.Consumer<O> consumer)
        Try to consume last result or resend exception.
        Parameters:
        consumer - The consumer to be executed
        Returns:
        Try for further processing
      • elseThrow

        public TryWithResult<O> elseThrow()
        Throws exception if present.
        Returns:
        TryWithResult for further processing
      • elseCatch

        public TryWithResult<O> elseCatch​(java.util.function.Consumer<IgnorableMappingException> exceptionConsumer)
        Consume exception if present.
        Parameters:
        exceptionConsumer - The consumer to be executed with the exception
        Returns:
        TryWithResult for further processing
      • ok

        public java.util.Optional<@Nullable O> ok()
        Get the result as optional.
        Returns:
        The result as optional
      • okOrNull

        public @Nullable O okOrNull()
        Get the result or null.
        Returns:
        The result as optional