diff --git a/packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler_Legacy.cpp b/packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler_Legacy.cpp index 53929ef00ac700..577eda29308131 100644 --- a/packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler_Legacy.cpp +++ b/packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler_Legacy.cpp @@ -170,6 +170,9 @@ void RuntimeScheduler_Legacy::callExpiredTasks(jsi::Runtime& runtime) { } } catch (jsi::JSError& error) { onTaskError_(runtime, error); + } catch (std::exception& ex) { + jsi::JSError error(runtime, std::string("Non-js exception: ") + ex.what()); + onTaskError_(runtime, error); } currentPriority_ = previousPriority; @@ -233,6 +236,9 @@ void RuntimeScheduler_Legacy::startWorkLoop(jsi::Runtime& runtime) { } } catch (jsi::JSError& error) { onTaskError_(runtime, error); + } catch (std::exception& ex) { + jsi::JSError error(runtime, std::string("Non-js exception: ") + ex.what()); + onTaskError_(runtime, error); } currentPriority_ = previousPriority; diff --git a/packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler_Modern.cpp b/packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler_Modern.cpp index 0a05dd76b33b4a..7a6eddf8506bc5 100644 --- a/packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler_Modern.cpp +++ b/packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler_Modern.cpp @@ -386,6 +386,9 @@ void RuntimeScheduler_Modern::executeTask( } } catch (jsi::JSError& error) { onTaskError_(runtime, error); + } catch (std::exception& ex) { + jsi::JSError error(runtime, std::string("Non-js exception: ") + ex.what()); + onTaskError_(runtime, error); } } @@ -420,6 +423,10 @@ void RuntimeScheduler_Modern::performMicrotaskCheckpoint( } } catch (jsi::JSError& error) { onTaskError_(runtime, error); + } catch (std::exception& ex) { + jsi::JSError error( + runtime, std::string("Non-js exception: ") + ex.what()); + onTaskError_(runtime, error); } retries++; } diff --git a/packages/react-native/ReactCommon/react/runtime/ReactInstance.cpp b/packages/react-native/ReactCommon/react/runtime/ReactInstance.cpp index bb19ff78d8b0b7..f6c07d7ff79a87 100644 --- a/packages/react-native/ReactCommon/react/runtime/ReactInstance.cpp +++ b/packages/react-native/ReactCommon/react/runtime/ReactInstance.cpp @@ -103,6 +103,10 @@ ReactInstance::ReactInstance( } } catch (jsi::JSError& originalError) { jsErrorHandler->handleError(jsiRuntime, originalError, true); + } catch (std::exception& ex) { + jsi::JSError error( + jsiRuntime, std::string("Non-js exception: ") + ex.what()); + jsErrorHandler->handleError(jsiRuntime, error, true); } }); }