NS ENSURE TRUE

Summary

Macro

Returns return-value if expr evaluates to false.

Syntax

NS_ENSURE_TRUE( expr, return-value );


Usage

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;
}

Document Tags and Contributors

 Contributors to this page: teoli, Bastiaan Jacques
 Last updated by: Bastiaan Jacques,