enforce

Raise the specified exception of the provided expression evaluates to false.

Behavior is similar to assert() but throws an exception on failure.

package @safe
enforce
(
ExceptionClass
T...
)
(
bool val
,
string msg = ""
,
string file = __FILE__
,
size_t line = __LINE__
)

Examples

enforce!(OutOfRange, myvar)(myvar > 0, "myvar must be greater than 0");

Meta