expected

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 uses try catch block and constructs Expected with value or error.

  1. auto expected(Args args)
    template expected(alias fun, Hook = Abort)
    @safe
    expected
    (
    Args...
    )
    (
    auto ref Args args
    )
    if (
    is(typeof(fun(args)))
    )
  2. Expected!(T, E, Hook) expected(T value)
  3. Expected!(void, E, Hook) expected()

Members

Functions

expected
auto expected(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(expected!fn(1) == 1);
assert(expected!fn(42).error.msg == "don't panic");

Meta