if (xpcomExceptionClass == nsnull) { xpcomExceptionClass = env->FindClass("org/mozilla/xpcom/XPCOMException"); if (!xpcomExceptionClass) return; }
ThrowException(JNIEnv* env, const nsresult aErrorCode, const char* aMessage){  // Only throw this exception if one hasn't already been thrown, so we don't  // mask a previous exception/error.  if (env->ExceptionCheck())    return;  // If the error code we get is for an Out Of Memory error, try to throw an  // OutOfMemoryError.  The JVM may have enough memory to create this error.  if (aErrorCode == NS_ERROR_OUT_OF_MEMORY) {    jclass clazz = env->FindClass("java/lang/OutOfMemoryError");    if (clazz) {      env->ThrowNew(clazz, aMessage);    }    env->DeleteLocalRef(clazz);    return;  }  // If the error was not handled above, then create an XPCOMException with the  // given error code and message.  // Create parameters and method signature. Max of 2 params.  The error code  // comes before the message string.  PRUint32 index = 0;  jvalue* args = new jvalue[2];  if (!args) {    ThrowException(env, NS_ERROR_OUT_OF_MEMORY,                   "Out of memory while throwing another exception");    return;  }  nsCAutoString methodSig("(");  if (aErrorCode) {    args[index++].j = aErrorCode;    methodSig.Append('J');  }  if (aMessage) {    args[index].l = env->NewStringUTF(aMessage);    if (args[index].l == nsnull) {      delete[] args;      return;    }    methodSig.AppendLiteral("Ljava/lang/String;");  }  methodSig.AppendLiteral(")V");  // create exception object  jthrowable throwObj = nsnull;  jmethodID mid = env->GetMethodID(xpcomExceptionClass, "<init>",                                   methodSig.get());  if (mid) {    throwObj = (jthrowable) env->NewObjectA(xpcomExceptionClass, mid, args);  }  NS_ASSERTION(throwObj, "Failed to create XPCOMException object");  // throw exception  if (throwObj) {    env->Throw(throwObj);  }  // cleanup  delete[] args;}