expectErr

Unwraps a result, yielding the content of an error value. If there is none, or success value, it throws assert(0) with the provided message.

  1. E expectErr(EX res, string msg)
    ref
    E
    expectErr
    (
    EX : Expected!(T, E, H)
    T
    E
    H
    )
    (
    auto ref EX res
    ,
    lazy string msg
    )
  2. E expectErr(EX res)

Parameters

res EX

Expected to check the result of

msg string

message to use with assert

Examples

assert(err("foo").expectErr("oops") == "foo");
version (D_Exceptions)
{
    () @trusted
    {
        assert(collectExceptionMsg!Throwable(Expected!int.init.expectErr("oops")) == "oops: empty");
        assert(collectExceptionMsg!Throwable(ok(42).expectErr("oops")) == "oops: 42");
        assert(collectExceptionMsg!Throwable(ok().expectErr("oops")) == "oops: empty"); // void value
    }();
}

assert(ok("foo").expect!(a => "bar") == "foo");
assert(err!string("foo").expect!(a => "bar") == "bar");
assert(err!string("foo").expect!((a) {}) is null);

assert(ok("foo").expectErr!(a => "bar") == "bar");
assert(err!string("foo").expectErr!(a => "bar") == "foo");
assert(ok!string("foo").expectErr!((a) {}) is null);

Meta