Note: This website is archived. For up-to-date information about D projects and development, please visit


Part of TutorialFundamentals


Using assert is a form of testing the code that you write. An assert statement takes an expression as it's first argument, and if that expression evaluates to true, then nothing happens. If however the expression evaluates to false, the statement will raise an AssertError and will print out an error message plus an additional string if it's provided as a second argument.


import std.stdio;

void main() 
    assert(221 % 5 == 1);
    assert(25 * (4 * 20) + 4 == 2004);
    assert(2 == 4, "2 is not equal to 4!");

More Information

More info can be found in the D Specification.