Macro
Returns return-value if expr evaluates to false.
NS_ENSURE_TRUE( expr, return-value );
nsresult mozMyClass::MozStringMucking() { char *foo = new char[123]; NS_ENSURE_TRUE(foo, NS_ERROR_OUT_OF_MEMORY); // This is equivalent to doing: if (!foo) return NS_ERROR_OUT_OF_MEMORY; // Thou shalt not return NS_ERROR_FAILURE.. int i = 3; NS_ENSURE_TRUE(i == 3, NS_ERROR_FAILURE); return NS_OK; } char* mozMyClass::DoStuff() { char* bar = new char[321]; NS_ENSURE_TRUE(bar, nsnull); return bar; }