Mozilla's getting a new look. What do you think? https://mzl.la/brandsurvey

 

Summary

Macro

Don't use NS_ASSERTION in new code that you write; instead, use NS_ABORT_IF_FALSE, because in that case a failure of the assertion results in a program abort that can't be ignored (so you'll find out if your code is wrong much sooner, hopefully while the code's still fresh in your memory).  Only convert old code if you're absolutely certain an assertion always holds.

Throws an assertion failure if the first macro argument does not evaluate to true. In a debug build the failure text is written to console (stderr), into the NSPR debug log, and on Windows a dialog box is opened. The behavior of an assertion failure can be controlled using the XPCOM_DEBUG_BREAK environment variable.

An assertion failure should be thrown on critical program errors only. A triggered assertion failure is equivalent to crashing in Tinderbox tests.

Note on terminology: "assertion" is the condition to test. There is always an assertion in NS_ASSERTION; it is the first argument. Only if the assertion evaluates to false is there an "assertion failure", which is thrown. The phrase "throwing an assertion" makes no sense.

Syntax

NS_ASSERTION(expressionToTest, "error text");

See also

Document Tags and Contributors

 Contributors to this page: teoli, Waldo, Sheppy, Jorend, Allanbonadio, Nickolay, Editmonkey, Biesi
 Last updated by: Waldo,