Skip to content

Commit 26f57c6

Browse files
authored
Merge pull request #22 from master-atul/develop
Develop
2 parents 163f3bc + 15b2240 commit 26f57c6

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

README.md

+20-1
Original file line numberDiff line numberDiff line change
@@ -381,14 +381,33 @@ setNativeExceptionHandler((errorString) => {
381381
*More Examples can be found in the examples folder*
382382
- Preserving old handler (thanks to zeh)
383383

384+
# Known issues and fixes:
385+
386+
### react-native-navigation (Wix)
387+
388+
This is specifically occuring when you use [wix library](http://wix.github.io/react-native-navigation/) for navigation along with react-native-exception-handler. Whenever an error occurs, it will recreate the application above the crash screen.
389+
390+
391+
**Fix:**
392+
393+
You need to set second parametera as *false* while calling _setNativeExceptionHandler_.
394+
The second parameter is an android specific field which stands for forceQuitOnError.
395+
When set to false it doesnt quit the app forcefully on error. In short :
396+
397+
Credit goes to **Gustavo Fão Valvassori**
398+
399+
```js
400+
setNativeExceptionHandler(nativeErrorCallback, false);
401+
```
402+
384403

385404
## CONTRIBUTORS
386405
- [Atul R](https://github.com/master-atul)
387406
- [Zeh Fernando](https://github.com/zeh)
388407
- [Fred Chasen](https://github.com/fchasen)
389408
- [Christoph Jerolimov](https://github.com/jerolimov)
390409
- [Peter Chow](https://github.com/peteroid)
391-
410+
- [Gustavo Fão Valvassori](https://github.com/faogustavo)
392411
## TESTING NATIVE EXCEPTIONS/ERRORS
393412

394413
To make sure this module works. You can generate a native exception using the module `rn-test-exception-handler`.

android/src/main/java/com/masteratul/exceptionhandler/ReactNativeExceptionHandlerModule.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,29 @@ public String getName() {
2828

2929

3030
@ReactMethod
31-
public void setHandlerforNativeException(Callback customHandler){
31+
public void setHandlerforNativeException(Callback customHandler, final boolean forceToQuit){
3232
callbackHolder = customHandler;
33+
3334
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
3435
@Override
3536
public void uncaughtException(Thread thread, Throwable throwable) {
3637
activity = getCurrentActivity();
3738
String stackTraceString = Log.getStackTraceString(throwable);
3839
callbackHolder.invoke(stackTraceString);
3940
Log.d("ERROR",stackTraceString);
41+
42+
4043
Intent i = new Intent();
4144
i.setClass(activity, errorIntentTargetClass);
4245
i.putExtra("stack_trace_string",stackTraceString);
4346
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
47+
4448
activity.startActivity(i);
45-
System.exit(0);
49+
activity.finish();
50+
51+
if (forceToQuit) {
52+
System.exit(0);
53+
}
4654
}
4755
});
4856
}

index.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
import {NativeModules} from 'react-native';
2+
import {NativeModules, Platform} from 'react-native';
33

44
const {ReactNativeExceptionHandler} = NativeModules;
55

@@ -17,11 +17,16 @@ export const setJSExceptionHandler = (customHandler = noop, allowedInDevMode = f
1717

1818
export const getJSExceptionHandler = () => global.ErrorUtils.getGlobalHandler();
1919

20-
export const setNativeExceptionHandler = (customErrorHandler = noop) => {
20+
export const setNativeExceptionHandler = (customErrorHandler = noop, forceApplicationToQuit = true) => {
2121
if (typeof customErrorHandler !== 'function') {
2222
customErrorHandler = noop;
2323
}
24-
ReactNativeExceptionHandler.setHandlerforNativeException(customErrorHandler);
24+
25+
if (Platform.OS === 'ios') {
26+
ReactNativeExceptionHandler.setHandlerforNativeException(customErrorHandler);
27+
} else {
28+
ReactNativeExceptionHandler.setHandlerforNativeException(customErrorHandler, forceApplicationToQuit);
29+
}
2530
};
2631

2732
export default {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-exception-handler",
3-
"version": "2.4.0",
3+
"version": "2.4.1",
44
"description": "A react native module that lets you to register a global error handler that can capture fatal/non fatal uncaught exceptions.",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)