Friday, April 19, 2013

jni jnienv ExceptionOccurred example c c++ java


ExceptionOccurred


jthrowable ExceptionOccurred(JNIEnv *env);

Determines if an exception is being thrown. The exception stays being thrown until either the native code calls ExceptionClear(), or the Java code handles the exception.
LINKAGE:
Index 15 in the JNIEnv interface function table.
PARAMETERS of ExceptionOccurred

env: the JNI interface pointer.

RETURNS:

Returns the exception object that is currently in the process of being thrown, or NULL if no exception is currently being thrown.

Example - ExceptionOccurred


jint result = env->CallIntMethodA(javaObj, methodId, params);
jthrowable exc = env->ExceptionOccurred();
if(exc)
{
    jclass objCls = env->FindClass("com/mycompany/myapp/exception/MyException");
    jmethodID codeMethod = env->GetMethodID(objCls, "getCustomCode", "()I");
    if(!objCls || !codeMethod){ ........ }
    // Try to execute getCustomCode java method.
    jint codeResult = env->CallIntMethod((jobject)exc, codeMethod);
    ...
    ...
}