assert(expression, error)

Tomek Sowiński just at ask.me
Sat Feb 12 05:45:21 PST 2011


spir napisał:

> Is there a way to specify what error to throw using (a variant of) assert:
>      assert(n > 0, new ValueError("..."));
> 
> (Sure, one can write:
>      if (n <= 0)
>          throw new ValueError("..."));
> but the same remark applies to plain assert: the whole point of assert is to 
> have it as builtin feature with clear application field & well-known semantics, 
> shared by the community of D programmers.)

With built-in assert, no. But std.exception can do it.

enforce(n > 0, new ValueError("..."));

-- 
Tomek



More information about the Digitalmars-d-learn mailing list