B2G/gecko/storage/test/unit/head_storage.js
/**
 * Invoke the given function and assert that it throws an exception expressing
 * the provided error code in its 'result' attribute.  JS function expressions
 * can be used to do this concisely.
 *
 * Example:
 *  expectError(Cr.NS_ERROR_INVALID_ARG, function() explodingFunction());
 *
 * @param aErrorCode
 *        The error code to expect from invocation of aFunction.
 * @param aFunction
 *        The function to invoke and expect an XPCOM-style error from.
 */
Invoke the given function and assert that it throws an exception expressing
the provided error code in its 'result' attribute.  JS function expressions
can be used to do this concisely.



@param aErrorCode
The error code to expect from invocation of aFunction.
@param aFunction
The function to invoke and expect an XPCOM-style error from.
Invoke the given function and assert that it throws an exception expressing the provided error code in its ' result ' attribute . JS function expressions can be used to do this concisely . @param aErrorCode The error code to expect from invocation of aFunction . @param aFunction The function to invoke and expect an XPCOM - style error from .
function expectError(aErrorCode, aFunction)
{
  let exceptionCaught = false;
  try {
    aFunction();
  }
  catch(e) {
    if (e.result != aErrorCode) {
      do_throw("Got an exception, but the result code was not the expected " +
               "one.  Expected " + aErrorCode + ", got " + e.result);
    }
    exceptionCaught = true;
  }
  if (!exceptionCaught)
    do_throw(aFunction + " should have thrown an exception but did not!");
}
function expectError ( aErrorCode , aFunction ) { let exceptionCaught = false ; try { aFunction ( ) ; } catch ( e ) { if ( e . result != aErrorCode ) { do_throw ( "Got an exception, but the result code was not the expected " + "one.  Expected " + aErrorCode + ", got " + e . result ) ; } exceptionCaught = true ; } if ( ! exceptionCaught ) do_throw ( aFunction + " should have thrown an exception but did not!" ) ; }
Invoke the given function and assert that it throws an exception expressing
 the provided error code in its 'result' attribute.
Invoke the given function and assert that it throws an exception expressing the provided error code in its ' result ' attribute .