JNI Throw是否会中断方法执行?

sb2*_*b27 4 c++ java java-native-interface

当我调用时env->ThrowNew(clazz, "..."),会不会停止随后执行C ++ / C方法,还是我必须自己停止它?

// 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;
}
Run Code Online (Sandbox Code Playgroud)

当我调用load_main_class方法,找不到类并ThrowNew调用该方法时会发生什么?

Ale*_*ohn 5

JNI异常不会立即中断本机方法的执行。但是,如果您不能正确处理此异常,那么任何JNI函数调用(除了很少的明确清除的函数调用)都会崩溃。