T - public abstract class Try<T> extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
Try.Func<T,R,E extends Throwable>
A Function that throws an Exception.
|
| Constructor and Description |
|---|
Try() |
| Modifier and Type | Method and Description |
|---|---|
static <U> Try<U> |
fail(Throwable e)
Create a try wrapping an Exception.
|
abstract <U> Try<U> |
flatMap(Function<? super T,? extends Try<U>> f)
Apply a function to the Try that itself returns a Try.
|
abstract <U> Try<U> |
map(Function<? super T,? extends U> f)
Apply a function to the Try.
|
abstract Try<T> |
mapFailure(Function<? super Throwable,? extends 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,
String m)
A try with a null check.
|
abstract Try<T> |
onFailure(Consumer<? super Throwable> f) |
abstract Try<T> |
onSuccess(Consumer<? super T> s) |
abstract T |
orElseThrow()
Recover the value or throw an Exception.
|
abstract <E extends Throwable> |
orElseThrow(Function<? super Throwable,E> f)
Recover the value or throw an exception created by applying the exception mapping function
to a failure.
|
abstract T |
recover(Function<? super 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, 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(Throwable e)
e - The Exception. Must not be null.public abstract T orElseThrow() throws RuntimeException
Exception - if the Try resulted in a Failure.RuntimeExceptionpublic abstract <E extends Throwable> T orElseThrow(Function<? super Throwable,E> f) throws E extends Throwable
f - The exception mapping function.E - The type of the resultant exception when a failure.E extends Throwablepublic abstract T recover(Function<? super Throwable,? extends T> f)
f - A function taking the exception.public abstract <U> Try<U> map(Function<? super T,? extends U> f)
f - The Function to apply.public abstract Try<T> mapFailure(Function<? super Throwable,? extends Throwable> f)
f - The failure mapping function.public abstract <U> Try<U> flatMap(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.Copyright © 2023. All rights reserved.