diff --git a/ReactAndroid/src/main/jni/react/JSCExecutor.cpp b/ReactAndroid/src/main/jni/react/JSCExecutor.cpp index ad9f3c05a..56af90b9b 100644 --- a/ReactAndroid/src/main/jni/react/JSCExecutor.cpp +++ b/ReactAndroid/src/main/jni/react/JSCExecutor.cpp @@ -126,13 +126,17 @@ JSCExecutor::JSCExecutor( } JSCExecutor::~JSCExecutor() { - *m_isDestroyed = true; - if (m_messageQueueThread->isOnThread()) { - terminateOnJSVMThread(); - } else { - m_messageQueueThread->runOnQueueSync([this] () { + try { + *m_isDestroyed = true; + if (m_messageQueueThread->isOnThread()) { terminateOnJSVMThread(); - }); + } else { + m_messageQueueThread->runOnQueueSync([this] () { + terminateOnJSVMThread(); + }); + } + } catch (...) { + Exceptions::handleUncaughtException(); } } diff --git a/ReactAndroid/src/main/jni/react/Platform.cpp b/ReactAndroid/src/main/jni/react/Platform.cpp index 03edca72c..3e1c700b7 100644 --- a/ReactAndroid/src/main/jni/react/Platform.cpp +++ b/ReactAndroid/src/main/jni/react/Platform.cpp @@ -20,10 +20,14 @@ LoadScriptFromAssets loadScriptFromAssets; namespace PerfLogging { InstallNativeHooks installNativeHooks; -} +}; namespace JSLogging { JSCNativeHook nativeHook = nullptr; -} +}; + +namespace Exceptions { +HandleUncaughtException handleUncaughtException; +}; } } diff --git a/ReactAndroid/src/main/jni/react/Platform.h b/ReactAndroid/src/main/jni/react/Platform.h index c5c1c5043..5ad664dbf 100644 --- a/ReactAndroid/src/main/jni/react/Platform.h +++ b/ReactAndroid/src/main/jni/react/Platform.h @@ -34,7 +34,7 @@ extern LoadScriptFromAssets loadScriptFromAssets; namespace PerfLogging { using InstallNativeHooks = std::function; extern InstallNativeHooks installNativeHooks; -} +}; namespace JSLogging { using JSCNativeHook = JSValueRef (*) ( @@ -44,6 +44,11 @@ namespace JSLogging { size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception); extern JSCNativeHook nativeHook; -} +}; + +namespace Exceptions { + using HandleUncaughtException = std::function; + extern HandleUncaughtException handleUncaughtException; +}; } } diff --git a/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp b/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp index 5081bd67f..fad41e7cc 100644 --- a/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp +++ b/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp @@ -865,6 +865,9 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { return std::unique_ptr( JMessageQueueThread::currentMessageQueueThread().release()); }; + Exceptions::handleUncaughtException = [] () { + translatePendingCppExceptionToJavaException(); + }; PerfLogging::installNativeHooks = addNativePerfLoggingHooks; JSLogging::nativeHook = nativeLoggingHook;