Suppose I have a Java class like this:
public class Test
{
static { System.loadLibrary("test"); }
public native int foo();
}
Suppose that the foo() method is doing some JNI calls, and one of these calls fails (IE, throws an exception). I would then like to return from the JNI code and have the exception thrown in Java. For example:
jint Java_Test_foo(JNIEnv* env, jobject thiz)
{
jstring foobar = (*env)->NewStringUTF(env, "Hello from JNI !");
if(foobar == NULL) // Not enough memory. OutOfMemoryError is thrown
return NULL; // Return immediately to get exception thrown in Java
// Do other stuff
...
return some_computed_jint;
}
The problem is that return NULL
is not a jint. In Android for example, I would get this warning when compiling:
warning: return makes integer from pointer without a cast.
Now the question is: What should I return in case of an Exception being thrown inside a JNI method that returns a jint?