Function frontOrThrow
Same as frontOr
except it throws an error if it can't get the value
auto frontOrThrow(alias makeThrowable, T)
(
auto ref T value
);
auto frontOrThrow(T, U)
(
auto ref T value,
lazy U throwable
);
Parameters
Name | Description |
---|---|
value | the value to resolve |
makeThrowable | the predicate that creates exception value cannot be resolved |
throwable | the value to throw if value cannot be resolved |
Returns
Nullable!T
: value .get
or throwOptional!T
: value .front
or throwRange!T
: value .front
or throwExample
import std .exception: assertThrown, assertNotThrown;
""
.frontOrThrow(new Exception(""))
.assertThrown!Exception;
auto b = "yo"
.frontOrThrow(new Exception(""))
.assertNotThrown!Exception;
assert(b == 'y');