Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setNativeExceptionHandler callback is not being invoked on Android #62

Open
mark-friedman opened this issue Jun 19, 2018 · 9 comments
Open

Comments

@mark-friedman
Copy link
Contributor

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.

@a7ul
Copy link
Owner

a7ul commented Jun 19, 2018

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

@mark-friedman
Copy link
Contributor Author

@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
Copy link
Contributor Author

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.

@a7ul
Copy link
Owner

a7ul commented Jun 21, 2018

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

@mark-friedman
Copy link
Contributor Author

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

@Louies89
Copy link

Louies89 commented Sep 13, 2018

@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
Copy link

@master-atul
Any update on this ?

@a7ul
Copy link
Owner

a7ul commented Sep 26, 2018

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.

@Louies89
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants