Java Reference
In-Depth Information
* @param e The exception; may not be {@code null}.
*/
public Result(Exception e) {
Objects.requireNonNull(e, "exception to wrap");
this.result = Optional.empty();
this.exception = Optional.of(e);
}
/**
* Provides the result as an optional.
*
* @return The result in an option, if there is any; otherwise, the
* empty optional. Never {@code null}.
*/
public Optional<RESULT_T> getResult() {
return result;
}
/**
* Provide the exception represented by this result, or the empty optional
* if there is no such exception.
*
* @return The exception represented by this result.
*/
public Optional<Exception> getException() {
return exception;
}
/**
* Returns whether this instance was constructed with a result.
*
* @return Whether we have a result.
*/
public boolean hasResult() {
return result.isPresent();
}
/**
* Gets the result, if present; otherwise, throws a
* {@link java.util.NoSuchElementException} with the exception
* in the suppressed field.
*
* @return The result, if present.
* @throws java.util.NoSuchElementException If there is no result.
*/
public RESULT_T getOrDie() {
return result.orElseThrow(() -> {
NoSuchElementException ex = new NoSuchElementException(
"No element in result"
);
ex.addSuppressed(getException().orElseThrow(() ->
new RuntimeException("INTERNAL ERROR"))
Search WWH ::




Custom Search