MCPcopy Create free account
hub / github.com/catboost/catboost / RethrowExceptionFromJavaToCpp

Function RethrowExceptionFromJavaToCpp

library/cpp/jni/jni.cpp:107–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

105}
106
107void 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
125void Check() {
126 RethrowExceptionFromJavaToCpp();

Callers 1

CheckFunction · 0.85

Calls 13

EnvFunction · 0.85
TJniExceptionClass · 0.85
ExceptionCheckMethod · 0.80
ExceptionOccurredMethod · 0.80
ExceptionClearMethod · 0.80
GetObjectClassMethod · 0.80
ReleaseStringUTFCharsMethod · 0.80
GetJniEnvMethod · 0.45
GetMethod · 0.45
GetMethodIDMethod · 0.45
CallObjectMethodMethod · 0.45
GetStringUTFCharsMethod · 0.45

Tested by

no test coverage detected