errnoEnforce

Enforces that the given value is true, throwing an ErrnoException if it is not.

alias errnoEnforce = enforce!ErrnoException

Return Value

value, if cast(bool) value is true. Otherwise, new ErrnoException(msg) is thrown. It is assumed that the last operation set errno to an error code corresponding with the failed condition.

Examples

import core.stdc.stdio : fclose, fgets, fopen;
import std.file : thisExePath;
import std.string : toStringz;

auto f = fopen(thisExePath.toStringz, "r").errnoEnforce;
scope(exit) fclose(f);
char[100] buf;
auto line = fgets(buf.ptr, buf.length, f);
enforce(line !is null); // expect a non-empty line

Meta