Package io.vavr.control
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
public static final class Try.Failure<T> extends java.lang.Object implements Try<T>, java.io.Serializable
Represents a failedTrycontaining aThrowableas 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:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.vavr.control.Try
Try.Failure<T>, Try.Success<T>, Try.WithResources1<T1 extends java.lang.AutoCloseable>, Try.WithResources2<T1 extends java.lang.AutoCloseable,T2 extends java.lang.AutoCloseable>, Try.WithResources3<T1 extends java.lang.AutoCloseable,T2 extends java.lang.AutoCloseable,T3 extends java.lang.AutoCloseable>, Try.WithResources4<T1 extends java.lang.AutoCloseable,T2 extends java.lang.AutoCloseable,T3 extends java.lang.AutoCloseable,T4 extends java.lang.AutoCloseable>, Try.WithResources5<T1 extends java.lang.AutoCloseable,T2 extends java.lang.AutoCloseable,T3 extends java.lang.AutoCloseable,T4 extends java.lang.AutoCloseable,T5 extends java.lang.AutoCloseable>, Try.WithResources6<T1 extends java.lang.AutoCloseable,T2 extends java.lang.AutoCloseable,T3 extends java.lang.AutoCloseable,T4 extends java.lang.AutoCloseable,T5 extends java.lang.AutoCloseable,T6 extends java.lang.AutoCloseable>, Try.WithResources7<T1 extends java.lang.AutoCloseable,T2 extends java.lang.AutoCloseable,T3 extends java.lang.AutoCloseable,T4 extends java.lang.AutoCloseable,T5 extends java.lang.AutoCloseable,T6 extends java.lang.AutoCloseable,T7 extends java.lang.AutoCloseable>, Try.WithResources8<T1 extends java.lang.AutoCloseable,T2 extends java.lang.AutoCloseable,T3 extends java.lang.AutoCloseable,T4 extends java.lang.AutoCloseable,T5 extends java.lang.AutoCloseable,T6 extends java.lang.AutoCloseable,T7 extends java.lang.AutoCloseable,T8 extends java.lang.AutoCloseable>
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Throwablecauseprivate static longserialVersionUID
-
Constructor Summary
Constructors Modifier Constructor Description privateFailure(java.lang.Throwable cause)Constructs a Failure.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object obj)Clarifies that values have a proper equals() method implemented.Tget()Returns the value of thisTryif it is aTry.Success, or throws the underlying exception if it is aTry.Failure.java.lang.ThrowablegetCause()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.booleanisFailure()Checks whether thisTryis aTry.Failure.booleanisSuccess()Checks whether thisTryis aTry.Success.java.lang.StringstringPrefix()Returns the name of this Value type, which is used by toString().java.lang.StringtoString()Clarifies that values have a proper toString() method implemented.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.vavr.control.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, transform
-
Methods inherited from interface io.vavr.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 Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
cause
private final java.lang.Throwable cause
-
-
Constructor Detail
-
Failure
private Failure(java.lang.Throwable cause)
Constructs a Failure.- Parameters:
cause- A cause of type Throwable, may not be null.- Throws:
java.lang.NullPointerException- ifcauseis null. Additionally, if the givencauseis fatal (i.e. non-recoverable), it is thrown sneakily without being declared in the method signature.
-
-
Method Detail
-
get
public T 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
public java.lang.Throwable 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
public boolean equals(java.lang.Object obj)
Description copied from interface:ValueClarifies that values have a proper equals() method implemented.
-
stringPrefix
public java.lang.String 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
public java.lang.String toString()
Description copied from interface:ValueClarifies that values have a proper toString() method implemented.See Object.toString().
-
-