A quick question:

Is it possible to return an arbitary exception from C++ XPCOM code, in the
same way as I might using 'throw' from within JavaScript?

Basically I'm looking for the DO_MAGICAL_RETURN_THING() macro in the code
below:

try
{
  authenticate("me", "mydogsname");
}
catch(e)
{
  alert(e);
}

function authenticate_js(user, secret) {
  if (user=="me")
  {
    if (secret == "mydogsname")
      this.access=true;
    else throw("Invalid password");
  }
  else throw("Invalid user");
}

NS_IMETHODIMP authenticate_cpp(const nsAReadableString& user, const
nsAReadableString& secret)
{
  if (user.Equals(NS_LITERAL_STRING("me")))
  {
    if (secret.Equals(NS_LITERAL_STRING("mydogsname")))
    {
      m_access = true;
    }
    else DO_MAGICAL_RETURN_THING("Invalid password");
  }
  else DO_MAGICAL_RETURN_THING("Invalid user");

  return NS_ERROR_MAGICAL_RETURN;
}

thanks in advance,
Hamish




Reply via email to