Does JNI Throw break the method execution?

sb27 :

When I call env->ThrowNew(clazz, "..."), will the subsequent execution of the C++/C method be stopped or do I have to stop it myself?

// This is the method which checks if a class can be loaded.

static inline jclass _check_find_class(JNIEnv* env, char* name) {
    jclass clazz = env->FindClass(name);

    if (clazz == NULL) {
        env->ThrowNew(env->FindClass("java/lang/NoClassDefFoundError"), message);
    }

    return clazz;
}

// This method is called in other functions like

jclass load_main_class(JNIEnv* env) {
    auto clazz = _check_find_class(env, "class/which/cannot/be/loaded");

    do_stuff(env, clazz);

    return clazz;
}

What is going to happen when I call load_main_class method, it isn't able to find the class and the ThrowNew method is called?

Alex Cohn :

A JNI exception does not immediately disrupt the native method execution. But if you don't handle this exception correctly, then any JNI function call (except the very few ones that are explicitly cleared) will crash.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=305214&siteId=1