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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With