Closed qtfreet00 closed 4 years ago
I can't seem to reproduce this issue. I have a single-file project with the following code:
#include <iostream>
#include <jnipp.h>
int main()
{
jni::Vm vm;
try {
jni::Class ctx("android/content/Context1");
}
catch (jni::NameResolutionException& e) {
std::cout << "the exception " << e.what() << std::endl;
}
std::cin.get();
return 0;
}
It is producing the following output, as expected:
the exception android/content/Context1
Can you give a more comprehensive example?
Note that the internal handleJavaExceptions()
function in the source code is for raising InvocationException
to indicate that an exeption was thrown in the Java stack that propagated up to the C++ code.
maybe i tested it on Android?
I changed findclass method like this
Class xx = env->FindClass(xxxx)
if(xx==nullptr){
jthrowable exception = env->ExceptionOccurred();
if (exception != nullptr) {
env->ExceptionClear();
throw NameResolutionException();
}
}
it works well
Aha, right you are. FindClass() raises a Java exception if it fails. I'll do a clear if this happens. Thanks for raising!
in demo,this action will crash ,because java class Context1 can not find
add handleJavaExcption for getClass getxxxField getxxxMethod before throw std::exception