| 61 | }; |
| 62 | |
| 63 | static std::string getMessage(JNIEnv *env, jthrowable throwable) { |
| 64 | |
| 65 | jclass clazz = env->FindClass("java/lang/Throwable"); |
| 66 | |
| 67 | jmethodID getMessage = env->GetMethodID(clazz, "toString", "()Ljava/lang/String;"); |
| 68 | if (getMessage == nullptr) { |
| 69 | return ""; |
| 70 | } |
| 71 | jstring message = (jstring) env->CallObjectMethod(throwable, getMessage); |
| 72 | if (env->ExceptionOccurred()) { |
| 73 | env->ExceptionClear(); |
| 74 | return JVM_ERROR_MSG; |
| 75 | } |
| 76 | if (message) { |
| 77 | // do whatever with mstr |
| 78 | std::string excp = JniStringToUTF(env, message); |
| 79 | env->DeleteLocalRef(message); |
| 80 | env->DeleteLocalRef(clazz); |
| 81 | return excp; |
| 82 | } |
| 83 | return ""; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Static function to throw the exception if one exists within the ENV. |
no test coverage detected