forked from organicmaps/organicmaps
Merge pull request #6157 from alexzatsepin/MAPSME-4068-handling-java-exceptions-precisely
[android] Added more precise handling of Java unchecked exceptions or…
This commit is contained in:
commit
7f836a82eb
2 changed files with 21 additions and 2 deletions
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include "base/assert.hpp"
|
||||
#include "base/exception.hpp"
|
||||
#include "base/logging.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
@ -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();
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include "ScopedLocalRef.hpp"
|
||||
|
||||
#include "base/logging.hpp"
|
||||
|
||||
#include "geometry/point2d.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
@ -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<jobject> make_global_ref(jobject obj);
|
||||
using TScopedLocalRef = ScopedLocalRef<jobject>;
|
||||
|
|
Loading…
Add table
Reference in a new issue