react-native-exception-handler
react-native-exception-handler copied to clipboard
setNativeExceptionHandler callback is not being invoked on Android
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.
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
@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.
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.
Will release your fix in v2.8.9. If that solves the problem, please close this issue. Thanks again 🌮
@master-atul I'm afraid that my fix (i.e., #67) wasn't for this issue, it was for issue #65.
@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 ?
@master-atul Any update on this ?
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.
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?