dsimcha wrote:
== Quote from Fawzi Mohamed ([email protected])'s article
I already thought that having a aassert (always assert) would
be nice...

In D2, isn't that what enforce() is for?

It is indeed.

I've found enforce() to be extremely practical. I use it every time I would otherwise write

  if (some test fails) throw new Exception("Some test failed");

Besides being slightly shorter than the above, it saves me the trouble of providing the file and line number where the error occurred. Also, its sibling errnoEnforce() is invaluable when working directly with C functions, where the alternative is

  if (some test fails) throw new Exception(to!string(strerror(errno)));

In fact, there are a lot of goodies in std.contracts that I suspect most people aren't aware of.

-Lars

Reply via email to