| 105 | } |
| 106 | |
| 107 | void RethrowExceptionFromJavaToCpp() { |
| 108 | auto* env = Env()->GetJniEnv(); |
| 109 | if (env->ExceptionCheck()) { |
| 110 | auto exc = TLocalRef(env->ExceptionOccurred()); |
| 111 | env->ExceptionClear(); |
| 112 | auto excClass = TLocalClassRef(env->GetObjectClass(exc.Get())); |
| 113 | jmethodID getMessage = env->GetMethodID(excClass.Get(), "getMessage", "()Ljava/lang/String;"); |
| 114 | auto message = static_cast<jstring>(env->CallObjectMethod(exc.Get(), getMessage)); |
| 115 | std::string exceptionMsg = "<no message>"; |
| 116 | if (message) { |
| 117 | char const* msg = env->GetStringUTFChars(message, nullptr); |
| 118 | exceptionMsg = msg; |
| 119 | env->ReleaseStringUTFChars(message, msg); |
| 120 | } |
| 121 | THROW(TJniException().append(exceptionMsg)); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | void Check() { |
| 126 | RethrowExceptionFromJavaToCpp(); |
no test coverage detected