将ExceptionDescribe转换为字符串

我需要在JNI中将ExceptionDescribe()的输出作为字符串获取,这样我就可以在文件中将其写入,而不是直接在命令行上编写它。 有什么办法或想法怎么做?

提前致谢,

萨米

您显然使用了ExceptionOccured()方法。

 jthrowable exc; exc = (*env)->ExceptionOccurred(env); 

ExceptionOccurred是第一步,获取可以执行的消息和堆栈跟踪:

  jboolean isCopy = false; jmethodID toString = env->GetMethodID(env->FindClass("java/lang/Object"), "toString", "()Ljava/lang/String;"); jstring s = (jstring)(*env)->CallObjectMethod(exc, toString); const char* utf = (*env)->GetStringUTFChars(s, &isCopy);