consume

Constructs Expected from the result of the provided function.

If the function is nothrow, it just returns it's result using Expected.

If not, then it consumes it's possible Exception using try catch block and constructs Expected in regards of the result.

template consume(alias fun, Hook = Abort)
consume
(
Args...
)
(
auto ref Args args
)
if (
is(typeof(fun(forward!args)))
)

Members

Functions

consume
auto consume(Args args)
Undocumented in source. Be warned that the author may not have intended to support it.

Examples

auto fn(int v) { if (v == 42) throw new Exception("don't panic"); return v; }

assert(consume!fn(1) == 1);
assert(consume!fn(42).error.msg == "don't panic");

Meta