ErrnoException.enforceRetCode

Calls enforceRet interpreting return value as error code

Wraps enforceRet with a lambda that verifies that return value is zero (success code). Any non-zero return value of Func is interpreted as a failure.

class ErrnoException
Caller!(typeof(&Func))
enforceRetCode
(
alias Func
)
(
istring file = __FILE__
,
int line = __LINE__
)

Return Value

Type: Caller!(typeof(&Func))

same as enforceRet

Examples

extern(C) static int func(int a, int b)
{
    .errno = EMFILE;
    test!("==")(a, 41);
    test!("==")(b, 43);
    return -1;
}

try
{
    (new ErrnoException).enforceRetCode!(func)().call(41, 43);
    test(false);
}
catch (ErrnoException e)
{
    test!("==")(e.message(), "func: Too many open files"[]);
    test!("==")(e.failedFunctionName(), "func"[]);
    test!("==")(e.line, __LINE__ - 7);
}

Meta