From 6dfaf67a07f4a55271f162b999f4b9ef09c77ca4 Mon Sep 17 00:00:00 2001 From: vvb2060 Date: Fri, 20 Aug 2021 14:50:56 +0800 Subject: [PATCH] [core] get full exception info (#955) --- core/src/main/cpp/main/include/jni_helper.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/main/cpp/main/include/jni_helper.h b/core/src/main/cpp/main/include/jni_helper.h index bf9135dc..47326b4a 100644 --- a/core/src/main/cpp/main/include/jni_helper.h +++ b/core/src/main/cpp/main/include/jni_helper.h @@ -156,9 +156,10 @@ concept ScopeOrObject = ScopeOrRaw; inline ScopedLocalRef ClearException(JNIEnv *env) { if (auto exception = env->ExceptionOccurred()) { env->ExceptionClear(); - static jmethodID toString = env->GetMethodID(env->FindClass("java/lang/Object"), "toString", - "()Ljava/lang/String;"); - auto str = (jstring) env->CallObjectMethod(exception, toString); + static jclass log = (jclass) env->NewGlobalRef(env->FindClass("android/util/Log")); + static jmethodID toString = env->GetStaticMethodID(log, "getStackTraceString", + "(Ljava/lang/Throwable;)Ljava/lang/String;"); + auto str = (jstring) env->CallStaticObjectMethod(log, toString, exception); env->DeleteLocalRef(exception); return {env, str}; }