public abstract class Try<T> extends Object
RFuture
and RPromise
.Modifier and Type | Class and Description |
---|---|
static class |
Try.Failure<T>
Represents a failed try.
|
static class |
Try.Success<T>
Represents a successful try.
|
Modifier and Type | Method and Description |
---|---|
static <T> Try<T> |
failure(Throwable cause)
Creates a failed try.
|
abstract <R> Try<R> |
flatMap(Function<? super T,Try<R>> func)
Maps successful tries through
func , passes failure through as is. |
abstract T |
get()
Returns the value associated with a successful try, or rethrows the exception if the try
failed.
|
abstract Throwable |
getFailure()
Returns the cause of failure for a failed try.
|
boolean |
isFailure()
Returns try if this is a failed try, false if it is a successful try.
|
abstract boolean |
isSuccess()
Returns try if this is a successful try, false if it is a failed try.
|
static <T,R> Function<Try<T>,Try<R>> |
lift(Function<T,R> func)
Lifts
func , a function on values, to a function on tries. |
abstract <R> Try<R> |
map(Function<? super T,R> func)
Maps successful tries through
func , passees failure through as is. |
abstract Try<T> |
recover(Function<? super Throwable,T> func)
Maps failed tries through
func , passes success through as is. |
static <T> Try<T> |
success(T value)
Creates a successful try.
|
public static <T> Try<T> success(T value)
public static <T,R> Function<Try<T>,Try<R>> lift(Function<T,R> func)
func
, a function on values, to a function on tries.public abstract T get()
cause
of
a newly constructed RuntimeException
.public abstract Throwable getFailure()
IllegalStateException
if
called on a successful try.public abstract boolean isSuccess()
public boolean isFailure()
public abstract <R> Try<R> map(Function<? super T,R> func)
func
, passees failure through as is.public abstract Try<T> recover(Function<? super Throwable,T> func)
func
, passes success through as is. Note: if func
throws an exception, you will get back a failure try with the new failure. Ideally one
could generalize the type T
here but Java doesn't allow type parameters with lower
bounds.Copyright © 2017. All rights reserved.