Skip to content

Commit

Permalink
Merge pull request #22 from master-atul/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
a7ul authored Nov 25, 2017
2 parents 163f3bc + 15b2240 commit 26f57c6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,33 @@ setNativeExceptionHandler((errorString) => {
*More Examples can be found in the examples folder*
- Preserving old handler (thanks to zeh)

# Known issues and fixes:

### react-native-navigation (Wix)

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.


**Fix:**

You need to set second parametera as *false* while calling _setNativeExceptionHandler_.
The second parameter is an android specific field which stands for forceQuitOnError.
When set to false it doesnt quit the app forcefully on error. In short :

Credit goes to **Gustavo Fão Valvassori**

```js
setNativeExceptionHandler(nativeErrorCallback, false);
```


## CONTRIBUTORS
- [Atul R](https://github.com/master-atul)
- [Zeh Fernando](https://github.com/zeh)
- [Fred Chasen](https://github.com/fchasen)
- [Christoph Jerolimov](https://github.com/jerolimov)
- [Peter Chow](https://github.com/peteroid)

- [Gustavo Fão Valvassori](https://github.com/faogustavo)
## TESTING NATIVE EXCEPTIONS/ERRORS

To make sure this module works. You can generate a native exception using the module `rn-test-exception-handler`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,29 @@ public String getName() {


@ReactMethod
public void setHandlerforNativeException(Callback customHandler){
public void setHandlerforNativeException(Callback customHandler, final boolean forceToQuit){
callbackHolder = customHandler;

Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable throwable) {
activity = getCurrentActivity();
String stackTraceString = Log.getStackTraceString(throwable);
callbackHolder.invoke(stackTraceString);
Log.d("ERROR",stackTraceString);


Intent i = new Intent();
i.setClass(activity, errorIntentTargetClass);
i.putExtra("stack_trace_string",stackTraceString);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

activity.startActivity(i);
System.exit(0);
activity.finish();

if (forceToQuit) {
System.exit(0);
}
}
});
}
Expand Down
11 changes: 8 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

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

const {ReactNativeExceptionHandler} = NativeModules;

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

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

export const setNativeExceptionHandler = (customErrorHandler = noop) => {
export const setNativeExceptionHandler = (customErrorHandler = noop, forceApplicationToQuit = true) => {
if (typeof customErrorHandler !== 'function') {
customErrorHandler = noop;
}
ReactNativeExceptionHandler.setHandlerforNativeException(customErrorHandler);

if (Platform.OS === 'ios') {
ReactNativeExceptionHandler.setHandlerforNativeException(customErrorHandler);
} else {
ReactNativeExceptionHandler.setHandlerforNativeException(customErrorHandler, forceApplicationToQuit);
}
};

export default {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-exception-handler",
"version": "2.4.0",
"version": "2.4.1",
"description": "A react native module that lets you to register a global error handler that can capture fatal/non fatal uncaught exceptions.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 26f57c6

Please sign in to comment.