T
- public abstract class Try<T>
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
Try.Func<T,R,E extends java.lang.Throwable>
A Function that throws an Exception.
|
Constructor and Description |
---|
Try() |
Modifier and Type | Method and Description |
---|---|
static <U> Try<U> |
fail(java.lang.Throwable e)
Create a try wrapping an Exception.
|
abstract <U> Try<U> |
flatMap(java.util.function.Function<? super T,? extends Try<U>> f)
Apply a function to the Try that itself returns a Try.
|
abstract <U> Try<U> |
map(java.util.function.Function<? super T,? extends U> f)
Apply a function to the Try.
|
abstract Try<T> |
mapFailure(java.util.function.Function<? super java.lang.Throwable,? extends java.lang.Throwable> f)
Map a failure by applying the exception mapping function.
|
static <U> Try<U> |
of(U value)
Create a Try from a value.
|
static <U> Try<U> |
ofNonNull(U value,
java.lang.String m)
A try with a null check.
|
abstract Try<T> |
onFailure(java.util.function.Consumer<? super java.lang.Throwable> f) |
abstract Try<T> |
onSuccess(java.util.function.Consumer<? super T> s) |
abstract T |
orElseThrow()
Recover the value or throw an Exception.
|
abstract <E extends java.lang.Throwable> |
orElseThrow(java.util.function.Function<? super java.lang.Throwable,E> f)
Recover the value or throw an exception created by applying the exception mapping function
to a failure.
|
abstract T |
recover(java.util.function.Function<? super java.lang.Throwable,? extends T> f)
Recover the value or apply a function to the exception to
get result.
|
abstract <U> Try<U> |
trying(Try.Func<? super T,? extends U,?> f)
Try a Function that might throw a Exception.
|
public static <U> Try<U> of(U value)
value
- A value. May be null.public static <U> Try<U> ofNonNull(U value, java.lang.String m)
value
- The value.m
- A message that will be added to the NullPointerException if the value is null. May be null.public static <U> Try<U> fail(java.lang.Throwable e)
e
- The Exception. Must not be null.public abstract T orElseThrow() throws java.lang.RuntimeException
java.lang.Exception
- if the Try resulted in a Failure.java.lang.RuntimeException
public abstract <E extends java.lang.Throwable> T orElseThrow(java.util.function.Function<? super java.lang.Throwable,E> f) throws E extends java.lang.Throwable
f
- The exception mapping function.E
- The type of the resultant exception when a failure.E extends java.lang.Throwable
public abstract T recover(java.util.function.Function<? super java.lang.Throwable,? extends T> f)
f
- A function taking the exception.public abstract <U> Try<U> map(java.util.function.Function<? super T,? extends U> f)
f
- The Function to apply.public abstract Try<T> mapFailure(java.util.function.Function<? super java.lang.Throwable,? extends java.lang.Throwable> f)
f
- The failure mapping function.public abstract <U> Try<U> flatMap(java.util.function.Function<? super T,? extends Try<U>> f)
f
- The Function to apply.public abstract <U> Try<U> trying(Try.Func<? super T,? extends U,?> f)
f
- The Function to apply.