diff --git a/packages/react-native/Libraries/Core/ExceptionsManager.js b/packages/react-native/Libraries/Core/ExceptionsManager.js index e64a3a0fd6e54f..09c5941f06240f 100644 --- a/packages/react-native/Libraries/Core/ExceptionsManager.js +++ b/packages/react-native/Libraries/Core/ExceptionsManager.js @@ -141,24 +141,27 @@ let inExceptionHandler = false; * Logs exceptions to the (native) console and displays them */ function handleException(e: mixed, isFatal: boolean) { - let error: Error; - if (e instanceof Error) { - error = e; - } else { - // Workaround for reporting errors caused by `throw 'some string'` - // Unfortunately there is no way to figure out the stacktrace in this - // case, so if you ended up here trying to trace an error, look for - // `throw ''` somewhere in your codebase. - error = new SyntheticError(e); - } - try { - inExceptionHandler = true; - /* $FlowFixMe[class-object-subtyping] added when improving typing for this - * parameters */ - // $FlowFixMe[incompatible-call] - reportException(error, isFatal, /*reportToConsole*/ true); - } finally { - inExceptionHandler = false; + // TODO(T196834299): We should really use a c++ turbomodule for this + if (!global.RN$handleException || !global.RN$handleException(e, isFatal)) { + let error: Error; + if (e instanceof Error) { + error = e; + } else { + // Workaround for reporting errors caused by `throw 'some string'` + // Unfortunately there is no way to figure out the stacktrace in this + // case, so if you ended up here trying to trace an error, look for + // `throw ''` somewhere in your codebase. + error = new SyntheticError(e); + } + try { + inExceptionHandler = true; + /* $FlowFixMe[class-object-subtyping] added when improving typing for this + * parameters */ + // $FlowFixMe[incompatible-call] + reportException(error, isFatal, /*reportToConsole*/ true); + } finally { + inExceptionHandler = false; + } } } diff --git a/packages/react-native/Libraries/Core/setUpErrorHandling.js b/packages/react-native/Libraries/Core/setUpErrorHandling.js index d1aaad73794060..32846d42f83506 100644 --- a/packages/react-native/Libraries/Core/setUpErrorHandling.js +++ b/packages/react-native/Libraries/Core/setUpErrorHandling.js @@ -21,13 +21,7 @@ ExceptionsManager.installConsoleErrorReporter(); if (!global.__fbDisableExceptionsManager) { const handleError = (e: mixed, isFatal: boolean) => { try { - // TODO(T196834299): We should really use a c++ turbomodule for this - if ( - !global.RN$handleException || - !global.RN$handleException(e, isFatal) - ) { - ExceptionsManager.handleException(e, isFatal); - } + ExceptionsManager.handleException(e, isFatal); } catch (ee) { console.log('Failed to print error: ', ee.message); throw e;