react-native-exception-handler icon indicating copy to clipboard operation
react-native-exception-handler copied to clipboard

setNativeExceptionHandler callback is not being invoked on Android

Open mark-friedman opened this issue 7 years ago • 9 comments
trafficstars

All I was trying to do was a console.log() in that callback.

    setNativeExceptionHandler((exceptionString) => {
      console.log(exceptionString);
    });

The exception that is being triggered is fairly deep in some native View rendering code (originally thrown, I believe, here, and then caught and rethrown here).

At first I set a breakpoint at that console.log() using the React Native debugger within Chrome and saw that the breakpoint was never getting reached.

Thinking that maybe there was some bad interaction between native code and the React Native debugger, I ran our app under the Android Studio debugger and set a breakpoint immediately before and after the invocation of the callback supplied to setNativeExceptionHandler (here). Doing so, I noticed the following message displayed in logcat during that invocation:

W/unknown:ReactNative: Invoking JS callback after bridge has been destroyed.

This could explain why we weren't seeing the result of the execution of that callback.

mark-friedman avatar Jun 19 '18 00:06 mark-friedman

Interesting. So, in some cases (maybe where the nesting is too deep) the exception is caught after the js bridge is destroyed.
Do you still see the native exception handler being invoked? @mark-friedman

a7ul avatar Jun 19 '18 03:06 a7ul

@master-atul, The native handler that is set by the call to Thread.setDefaultUncaughtExceptionHandler() (i.e., within setHandlerforNativeException()) is being invoked. Within that handler it attempts to invoke the JavaScript handler (i.e. callbackHolder). That invocation of the JavaScript handler is what yields the message about the JS callback bridge having been already destroyed.

mark-friedman avatar Jun 19 '18 20:06 mark-friedman

I realize that you might have asking if the native exception UI for react-native-exception-handler (i.e. the DefaultErrorScreen activity) was being shown and the answer to that is yes.

mark-friedman avatar Jun 19 '18 21:06 mark-friedman

Will release your fix in v2.8.9. If that solves the problem, please close this issue. Thanks again 🌮

a7ul avatar Jun 21 '18 05:06 a7ul

@master-atul I'm afraid that my fix (i.e., #67) wasn't for this issue, it was for issue #65.

mark-friedman avatar Jun 26 '18 16:06 mark-friedman

@master-atul Hi, setNativeExceptionHandler call back is nott getting triggered from native module.

my code is :

setNativeExceptionHandler((errorString) => {
  console.log('Unexpected error occurred setNativeExceptionHandler')
},false, true);

and the red screen shows as usual and when i check console it prints:

09-13 19:55:04.320 28936 28936 D ReactNative: CatalystInstanceImpl.destroy() start
09-13 19:55:04.326 28936 28973 D ReactNative: CatalystInstanceImpl.destroy() end
09-13 20:02:28.663 29998 29998 D ReactNative: ReactInstanceManager.ctor()
09-13 20:02:28.696 29998 29998 D ReactNative: ReactInstanceManager.createReactContextInBackground()
09-13 20:02:28.696 29998 29998 D ReactNative: ReactInstanceManager.recreateReactContextInBackgroundInner()
09-13 20:02:28.697 29998 29998 D ReactNative: ReactInstanceManager.onJSBundleLoadedFromServer()
09-13 20:02:28.698 29998 29998 D ReactNative: ReactInstanceManager.recreateReactContextInBackground()
09-13 20:02:28.699 29998 29998 D ReactNative: ReactInstanceManager.runCreateReactContextOnNewThread()
09-13 20:02:28.738 29998 30028 D ReactNative: ReactInstanceManager.createReactContext()
09-13 20:02:28.892 29998 30028 D ReactNative: Initializing React Xplat Bridge.
09-13 20:02:28.894 29998 30028 D ReactNative: Initializing React Xplat Bridge before initializeBridge
09-13 20:02:28.906 29998 30028 D ReactNative: Initializing React Xplat Bridge after initializeBridge
09-13 20:02:28.906 29998 30028 D ReactNative: CatalystInstanceImpl.runJSBundle()
09-13 20:02:28.908 29998 30045 D ReactNative: ReactInstanceManager.setupReactContext()
09-13 20:02:28.908 29998 30045 D ReactNative: CatalystInstanceImpl.initialize()
09-13 20:02:28.909 29998 30045 D ReactNative: ReactInstanceManager.attachRootViewToInstance()

after the error occurs.

Can you please assist ?

Louies89 avatar Sep 13 '18 14:09 Louies89

@master-atul Any update on this ?

Louies89 avatar Sep 26 '18 07:09 Louies89

Hi @Louies89

From the readme

NOTE: setNativeExceptionHandler only works in bundled mode - it will show the red screen when applied to dev mode.

If you are seeing red screen, it means you are in dev mode.

a7ul avatar Sep 26 '18 08:09 a7ul

Ooh Sorry, I missed it.... Thank you for this. But in dev mode 1st 2 times I got the exception screen.

Do not know how.

Is there a way to switch from dev mode to bundle mode while doing hot reloading?

Louies89 avatar Sep 26 '18 17:09 Louies89