Add exception handling in vanilla jni

Summary:
Exception handling in vanilla jni

## Changelog:
[Internal] [Added] Added exception handling for vanilla jni implementation in yoga

Reviewed By: amir-shalem

Differential Revision: D18036134

fbshipit-source-id: 965eaa2fddbc00b9ac0120b79678608e280d03db
This commit is contained in:
Sidharth Guglani 2019-10-22 10:45:20 -07:00 коммит произвёл Facebook Github Bot
Родитель 76ab5062e9
Коммит 25e4265fc7
2 изменённых файлов: 30 добавлений и 22 удалений

Просмотреть файл

@ -352,6 +352,7 @@ static void jni_YGNodeCalculateLayoutJNI(
jlongArray nativePointers,
jobjectArray javaNodes) {
try {
void* layoutContext = nullptr;
auto map = PtrJNodeMapVanilla{};
if (nativePointers) {
@ -371,6 +372,9 @@ static void jni_YGNodeCalculateLayoutJNI(
YGNodeStyleGetDirection(_jlong2YGNodeRef(nativePointer)),
layoutContext);
YGTransferLayoutOutputsRecursive(env, obj, root, layoutContext);
} catch (jthrowable throwable) {
env->Throw(throwable);
}
}
static void jni_YGNodeMarkDirtyJNI(

Просмотреть файл

@ -62,12 +62,16 @@ void logErrorMessageAndDie(const char* message) {
}
void assertNoPendingJniException(JNIEnv* env) {
// This method cannot call any other method of the library, since other
// methods of the library use it to check for exceptions too
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
logErrorMessageAndDie("Aborting due to pending Java exception in JNI");
if (env->ExceptionCheck() == JNI_FALSE) {
return;
}
auto throwable = env->ExceptionOccurred();
if (!throwable) {
logErrorMessageAndDie("Unable to get pending JNI exception.");
}
env->ExceptionClear();
throw throwable;
}
} // namespace vanillajni