Class Try.Failure<T>
java.lang.Object
io.vavr.control.Try.Failure<T>
- Type Parameters:
T- the type of the value that would have been contained if successful
- All Implemented Interfaces:
Try<T>, Value<T>, Serializable, Iterable<T>
Represents a failed
Try containing a Throwable as the cause.
Instances of this class indicate that the computation threw an exception and do not contain a successful value.
Try<Integer> failure = new Try.Failure<>(new RuntimeException("error"));
failure.isFailure(); // true
failure.getCause(); // RuntimeException: error
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface Try
Try.Failure<T>, Try.Success<T>, Try.WithResources1<T1>, Try.WithResources2<T1,T2>, Try.WithResources3<T1, T2, T3>, Try.WithResources4<T1, T2, T3, T4>, Try.WithResources5<T1, T2, T3, T4, T5>, Try.WithResources6<T1, T2, T3, T4, T5, T6>, Try.WithResources7<T1, T2, T3, T4, T5, T6, T7>, Try.WithResources8<T1, T2, T3, T4, T5, T6, T7, T8> -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanClarifies that values have a proper equals() method implemented.get()Returns the value of thisTryif it is aTry.Success, or throws the underlying exception if it is aTry.Failure.getCause()Returns the cause of failure if thisTryis aTry.Failure.inthashCode()Clarifies that values have a proper hashCode() method implemented.booleanisEmpty()Checks whether thisTrycontains no value, i.e., it is aTry.Failure.booleanChecks whether thisTryis aTry.Failure.booleanChecks whether thisTryis aTry.Success.Returns the name of this Value type, which is used by toString().toString()Clarifies that values have a proper toString() method implemented.Methods inherited from interface Try
andFinally, andFinallyTry, andThen, andThen, andThenTry, andThenTry, collect, failed, filter, filter, filter, filterTry, filterTry, filterTry, flatMap, flatMapTry, fold, getOrElseGet, getOrElseThrow, isAsync, isLazy, isSingleValued, iterator, map, mapFailure, mapTo, mapToVoid, mapTry, onFailure, onFailure, onSuccess, orElse, orElse, orElseRun, peek, recover, recover, recover, recoverAllAndTry, recoverAndTry, recoverWith, recoverWith, recoverWith, toEither, toEither, toValidation, toValidation, transformMethods inherited from interface Value
collect, collect, contains, corresponds, eq, exists, forAll, forEach, getOrElse, getOrElse, getOrElseThrow, getOrElseTry, getOrNull, out, out, spliterator, stderr, stdout, toArray, toCharSeq, toCompletableFuture, toEither, toEither, toInvalid, toInvalid, toJavaArray, toJavaArray, toJavaArray, toJavaCollection, toJavaList, toJavaList, toJavaMap, toJavaMap, toJavaMap, toJavaOptional, toJavaParallelStream, toJavaSet, toJavaSet, toJavaStream, toLeft, toLeft, toLinkedMap, toLinkedMap, toLinkedSet, toList, toMap, toMap, toOption, toPriorityQueue, toPriorityQueue, toQueue, toRight, toRight, toSet, toSortedMap, toSortedMap, toSortedMap, toSortedMap, toSortedSet, toSortedSet, toStream, toTree, toTree, toTry, toTry, toValid, toValid, toValidation, toValidation, toVector
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
cause
-
-
Constructor Details
-
Failure
Constructs a Failure.- Parameters:
cause- A cause of type Throwable, may not be null.- Throws:
NullPointerException- ifcauseis null. Additionally, if the givencauseis fatal (i.e. non-recoverable), it is thrown sneakily without being declared in the method signature.
-
-
Method Details
-
get
Description copied from interface:TryReturns the value of thisTryif it is aTry.Success, or throws the underlying exception if it is aTry.Failure.Important: If this
Tryis aTry.Failure, the exception thrown is exactly theTry.getCause()of thisFailure. The underlying cause is thrown sneakily (without being declared in the method signature). -
getCause
Description copied from interface:TryReturns the cause of failure if thisTryis aTry.Failure.- Specified by:
getCausein interfaceTry<T>- Returns:
- the throwable cause of this
Try.Failure
-
isEmpty
public boolean isEmpty()Description copied from interface:TryChecks whether thisTrycontains no value, i.e., it is aTry.Failure.- Specified by:
isEmptyin interfaceTry<T>- Specified by:
isEmptyin interfaceValue<T>- Returns:
trueif this is aTry.Failure,falseif this is aTry.Success
-
isFailure
public boolean isFailure()Description copied from interface:TryChecks whether thisTryis aTry.Failure.- Specified by:
isFailurein interfaceTry<T>- Returns:
trueif this is aTry.Failure,falseif this is aTry.Success
-
isSuccess
public boolean isSuccess()Description copied from interface:TryChecks whether thisTryis aTry.Success.- Specified by:
isSuccessin interfaceTry<T>- Returns:
trueif this is aTry.Success,falseif this is aTry.Failure
-
equals
Description copied from interface:ValueClarifies that values have a proper equals() method implemented. -
stringPrefix
Description copied from interface:ValueReturns the name of this Value type, which is used by toString().- Specified by:
stringPrefixin interfaceValue<T>- Returns:
- This type name.
-
hashCode
public int hashCode()Description copied from interface:ValueClarifies that values have a proper hashCode() method implemented.See Object.hashCode().
-
toString
Description copied from interface:ValueClarifies that values have a proper toString() method implemented.See Object.toString().
-