Class TryVoid
- java.lang.Object
-
- io.github.oliviercailloux.jaris.exceptions.TryVoid
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o2)
Returnstrue
iff the given object is aTry
and, either: this object and the given object are both successes; or this object and the given object are both failures and they encapsulate equal causes.static TryVoid
failure(Throwable cause)
Returns a failure encapsulating the given cause.Throwable
getCause()
If this object is a failure, returns the cause it encapsulates.int
hashCode()
boolean
isFailure()
Returnstrue
iff this object represents a failure; equivalently, iff it encapsulates a cause.boolean
isSuccess()
Returnstrue
iff this object represents a success.static TryVoid
run(Throwing.Runnable<Throwable> runnable)
Attempts to run the given runnable, and returns a success if it succeeds; or a failure encapsulating the exception thrown by the runnable if it threw one.static TryVoid
success()
Returns a success.String
toString()
Returns a string representation of this object, suitable for debug.
-
-
-
Method Detail
-
run
public static TryVoid run(Throwing.Runnable<Throwable> runnable)
Attempts to run the given runnable, and returns a success if it succeeds; or a failure encapsulating the exception thrown by the runnable if it threw one.- Returns:
- a success iff the given runnable did not throw an exception.
-
success
public static TryVoid success()
Returns a success.
-
failure
public static TryVoid failure(Throwable cause)
Returns a failure encapsulating the given cause.
-
isSuccess
public boolean isSuccess()
Returnstrue
iff this object represents a success.- Returns:
true
iffisFailure()
returnsfalse
-
isFailure
public boolean isFailure()
Returnstrue
iff this object represents a failure; equivalently, iff it encapsulates a cause.- Returns:
true
iffisSuccess()
returnsfalse
-
getCause
public Throwable getCause() throws IllegalStateException
If this object is a failure, returns the cause it encapsulates.- Throws:
IllegalStateException
- if this object is a success, thus, encapsulates no cause.- See Also:
isFailure()
-
equals
public boolean equals(Object o2)
Returnstrue
iff the given object is aTry
and, either: this object and the given object are both successes; or this object and the given object are both failures and they encapsulate equal causes.
-
-