diff --git a/CHANGELOG b/CHANGELOG index aaf77f9..4f79371 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,11 @@ CHANGELOG ========= +1.2.0 +----- + +* [result] orElseThrow() throws error within a CheckedErrorResultException + 1.1.0 ----- diff --git a/README.org b/README.org index 266002d..89230a7 100644 --- a/README.org +++ b/README.org @@ -821,7 +821,7 @@ **** =T orElseThrow()= Extracts the successful value from the result, or throws the error - =Throwable=. + within a =CheckedErrorResultException=. #+BEGIN_SRC java final Integer result = Result.of(() -> getValue()) diff --git a/src/main/java/net/kemitix/mon/result/CheckedErrorResultException.java b/src/main/java/net/kemitix/mon/result/CheckedErrorResultException.java new file mode 100644 index 0000000..47a1916 --- /dev/null +++ b/src/main/java/net/kemitix/mon/result/CheckedErrorResultException.java @@ -0,0 +1,46 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2018 Paul Campbell + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies + * or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE + * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package net.kemitix.mon.result; + +/** + * A checked wrapper for exceptions thrown within a {@link Result}. + * + *
Used by {@link Result#orElseThrow()} when the {@link Result} is an error.
+ * + * @author Paul Campbell (pcampbell@kemitix.net) + */ +public final class CheckedErrorResultException extends Exception { + + private CheckedErrorResultException(final Throwable cause) { + super(cause); + } + + /** + * Creates a new object. + * + * @param cause the cause + * @return a {@link CheckedErrorResultException} containing the cause + */ + static CheckedErrorResultException with(final Throwable cause) { + return new CheckedErrorResultException(cause); + } +} diff --git a/src/main/java/net/kemitix/mon/result/Err.java b/src/main/java/net/kemitix/mon/result/Err.java index 01bf9b5..e2c0a67 100644 --- a/src/main/java/net/kemitix/mon/result/Err.java +++ b/src/main/java/net/kemitix/mon/result/Err.java @@ -73,8 +73,8 @@ class ErrUsed by {@link Result#orElseThrowUnchecked()} when the {@link Result} is an error.
* diff --git a/src/main/java/net/kemitix/mon/result/Result.java b/src/main/java/net/kemitix/mon/result/Result.java index 35b29af..76d852b 100644 --- a/src/main/java/net/kemitix/mon/result/Result.java +++ b/src/main/java/net/kemitix/mon/result/Result.java @@ -96,23 +96,21 @@ public interface Result