diff --git a/android/jni/com/mapswithme/core/jni_helper.cpp b/android/jni/com/mapswithme/core/jni_helper.cpp index ec20c3b80a..0ef3db0b82 100644 --- a/android/jni/com/mapswithme/core/jni_helper.cpp +++ b/android/jni/com/mapswithme/core/jni_helper.cpp @@ -4,7 +4,6 @@ #include "base/assert.hpp" #include "base/exception.hpp" -#include "base/logging.hpp" #include @@ -199,12 +198,29 @@ bool HandleJavaException(JNIEnv * env) const jthrowable e = env->ExceptionOccurred(); env->ExceptionDescribe(); env->ExceptionClear(); - LOG(LERROR, (ToNativeString(env, e))); + my::LogLevel level = GetLogLevelForException(env, e); + LOG(level, (ToNativeString(env, e))); return true; } return false; } +my::LogLevel GetLogLevelForException(JNIEnv * env, const jthrowable & e) +{ + static jclass const errorClass = jni::GetGlobalClassRef(env, "java/lang/Error"); + ASSERT(errorClass, (jni::DescribeException())); + static jclass const runtimeExceptionClass = + jni::GetGlobalClassRef(env, "java/lang/RuntimeException"); + ASSERT(runtimeExceptionClass, (jni::DescribeException())); + // If Unchecked Exception or Error is occurred during Java call the app should fail immediately. + // In other cases, just a warning message about exception (Checked Exception) + // will be written into LogCat. + if (env->IsInstanceOf(e, errorClass) || env->IsInstanceOf(e, runtimeExceptionClass)) + return LERROR; + + return LWARNING; +} + std::string DescribeException() { JNIEnv * env = GetEnv(); diff --git a/android/jni/com/mapswithme/core/jni_helper.hpp b/android/jni/com/mapswithme/core/jni_helper.hpp index 35a5b334b1..4463fd11bd 100644 --- a/android/jni/com/mapswithme/core/jni_helper.hpp +++ b/android/jni/com/mapswithme/core/jni_helper.hpp @@ -4,6 +4,8 @@ #include "ScopedLocalRef.hpp" +#include "base/logging.hpp" + #include "geometry/point2d.hpp" #include @@ -47,6 +49,7 @@ char const * GetStringClassName(); std::string DescribeException(); bool HandleJavaException(JNIEnv * env); +my::LogLevel GetLogLevelForException(JNIEnv * env, const jthrowable & e); std::shared_ptr make_global_ref(jobject obj); using TScopedLocalRef = ScopedLocalRef;