Skip to content

Commit e03a7c4

Browse files
committed
Bumped version and added readme.
1 parent dca5aa6 commit e03a7c4

File tree

3 files changed

+46
-63
lines changed

3 files changed

+46
-63
lines changed

README.md

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ To tackle this we register a global error handler that could be used to for exam
2020
**V2 of this module now supports catching Unhandled Native Exceptions also along with the JS Exceptions ✌🏻🍻**
2121
There are **NO** breaking changes. So its safe to upgrade from v1 to v2. So there is no reason not to 😉.
2222

23+
**V2.9**
24+
- Adds support for executing previously set error handlers (now this module can work with other analytics modules)
25+
- Adds an improved approach for overwriting native error handlers.
26+
- Thanks @ [Damien Solimando](https://github.com/dsolimando)
27+
2328
**Example** repo can be found here:
2429
*[https://github.com/master-atul/react-native-exception-handler-example](https://github.com/master-atul/react-native-exception-handler-example) *
2530

@@ -128,7 +133,7 @@ setJSExceptionHandler((error, isFatal) => {
128133
// or hit google analytics to track crashes
129134
// or hit a custom api to inform the dev team.
130135
});
131-
136+
//=================================================
132137
// ADVANCED use case:
133138
const exceptionhandler = (error, isFatal) => {
134139
// your error handler function
@@ -156,17 +161,21 @@ setNativeExceptionHandler((exceptionString) => {
156161
//NOTE: alert or showing any UI change via JS
157162
//WILL NOT WORK in case of NATIVE ERRORS.
158163
});
159-
164+
//====================================================
160165
// ADVANCED use case:
161166
const exceptionhandler = (exceptionString) => {
162167
// your exception handler code here
163168
}
164-
setNativeExceptionHandler(exceptionhandler,forceAppQuit);
169+
setNativeExceptionHandler(exceptionhandler,forceAppQuit,executeDefaultHandler);
165170
// - exceptionhandler is the exception handler function
166171
// - forceAppQuit is an optional ANDROID specific parameter that defines
167-
// if the app should be force quit on error. default value is true.
168-
// To see usecase check the common issues section.
169-
172+
// if the app should be force quit on error. default value is true.
173+
// To see usecase check the common issues section.
174+
// - executeDefaultHandler is an optional boolean (both IOS, ANDROID)
175+
// It executes previous exception handlers if set by some other module.
176+
// It will come handy when you use any other crash analytics module along with this one
177+
// Default value is set to false. Set to true if you are using other analytics modules.
178+
170179
```
171180
It is recommended you set both the handlers.
172181

@@ -201,15 +210,15 @@ In Android and iOS you will see something like
201210
<img src="https://github.com/master-atul/react-native-exception-handler/raw/master/screens/ios_native_exception.png" width="300"/>
202211
</p>
203212

204-
**Modifying Android Native Exception handler UI** (NATIVE CODE HAS TO BE WRITTEN) *recommended that you do this in android studio*
213+
**Modifying Android Native Exception handler (RECOMMENDED APPROACH)**
205214

206-
- Create an Empty Activity in the `android/app/src/main/java/[...]/`. For example lets say CustomErrorDialog.java
207-
- Customize your activity to look and behave however you need it to be.
208-
- In the `android/app/src/main/java/[...]/MainApplication.java`
215+
(NATIVE CODE HAS TO BE WRITTEN) *recommended that you do this in android studio*
216+
217+
- In the `android/app/src/main/java/[...]/MainActivity.java`
209218

210219
```java
211220
import com.masteratul.exceptionhandler.ReactNativeExceptionHandlerModule;
212-
import <yourpackage>.YourCustomActivity; //This is your CustomErrorDialog.java
221+
import com.masteratul.exceptionhandler.NativeExceptionHandlerIfc
213222
...
214223
...
215224
...
@@ -221,18 +230,27 @@ public class MainApplication extends Application implements ReactApplication {
221230
....
222231
....
223232
....
224-
ReactNativeExceptionHandlerModule.replaceErrorScreenActivityClass(YourCustomActivity.class); //This will replace the native error handler popup with your own custom activity.
233+
ReactNativeExceptionHandlerModule.setNativeExceptionHandler(new NativeExceptionHandlerIfc() {
234+
@Override
235+
public void handleNativeException(Thread thread, Throwable throwable, Thread.UncaughtExceptionHandler originalHandler) {
236+
// Put your error handling code here
237+
}
238+
}//This will override the default behaviour of displaying the recover activity.
225239
}
226240

227241
```
228242

229-
**Modifying Android Native Exception handler** (NATIVE CODE HAS TO BE WRITTEN) *recommended that you do this in android studio*
243+
**Modifying Android Native Exception handler UI (CUSTOM ACTIVITY APPROACH (OLD APPROACH).. LEAVING FOR BACKWARD COMPATIBILITY)**
230244

231-
- In the `android/app/src/main/java/[...]/MainActivity.java`
245+
(NATIVE CODE HAS TO BE WRITTEN) *recommended that you do this in android studio*
246+
247+
- Create an Empty Activity in the `android/app/src/main/java/[...]/`. For example lets say CustomErrorDialog.java
248+
- Customize your activity to look and behave however you need it to be.
249+
- In the `android/app/src/main/java/[...]/MainApplication.java`
232250

233251
```java
234252
import com.masteratul.exceptionhandler.ReactNativeExceptionHandlerModule;
235-
import com.masteratul.exceptionhandler.NativeExceptionHandlerIfc
253+
import <yourpackage>.YourCustomActivity; //This is your CustomErrorDialog.java
236254
...
237255
...
238256
...
@@ -244,12 +262,7 @@ public class MainApplication extends Application implements ReactApplication {
244262
....
245263
....
246264
....
247-
ReactNativeExceptionHandlerModule.setNativeExceptionHandler(new NativeExceptionHandlerIfc() {
248-
@Override
249-
public void handleNativeException(Thread thread, Throwable throwable, Thread.UncaughtExceptionHandler originalHandler) {
250-
// Put your error handling code here
251-
}
252-
}//This will override the default behaviour of displaying the recover activity.
265+
ReactNativeExceptionHandlerModule.replaceErrorScreenActivityClass(YourCustomActivity.class); //This will replace the native error handler popup with your own custom activity.
253266
}
254267

255268
```

index.js

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,63 +4,33 @@ const { ReactNativeExceptionHandler } = NativeModules;
44

55
const noop = () => { };
66

7-
export const setJSExceptionHandler = (
8-
customHandler = noop,
9-
allowedInDevMode = false
10-
) => {
11-
if (
12-
typeof allowedInDevMode !== "boolean" ||
13-
typeof customHandler !== "function"
14-
) {
15-
console.log(
16-
"setJSExceptionHandler is called with wrong argument types.. first argument should be callback function and second argument is optional should be a boolean"
17-
);
18-
console.log(
19-
"Not setting the JS handler .. please fix setJSExceptionHandler call"
20-
);
7+
export const setJSExceptionHandler = (customHandler = noop, allowedInDevMode = false) => {
8+
if (typeof allowedInDevMode !== "boolean" || typeof customHandler !== "function"){
9+
console.log("setJSExceptionHandler is called with wrong argument types.. first argument should be callback function and second argument is optional should be a boolean");
10+
console.log("Not setting the JS handler .. please fix setJSExceptionHandler call");
2111
return;
2212
}
2313
const allowed = allowedInDevMode ? true : !__DEV__;
2414
if (allowed) {
2515
global.ErrorUtils.setGlobalHandler(customHandler);
2616
console.error = (message, error) => global.ErrorUtils.reportError(error); // sending console.error so that it can be caught
2717
} else {
28-
console.log(
29-
"Skipping setJSExceptionHandler: Reason: In DEV mode and allowedInDevMode = false"
30-
);
18+
console.log("Skipping setJSExceptionHandler: Reason: In DEV mode and allowedInDevMode = false");
3119
}
3220
};
3321

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

36-
export const setNativeExceptionHandler = (
37-
customErrorHandler = noop,
38-
forceApplicationToQuit = true,
39-
executeDefaultHandler = false
40-
) => {
41-
if (
42-
typeof customErrorHandler !== "function" ||
43-
typeof forceApplicationToQuit !== "boolean"
44-
) {
45-
console.log(
46-
"setNativeExceptionHandler is called with wrong argument types.. first argument should be callback function and second argument is optional should be a boolean"
47-
);
48-
console.log(
49-
"Not setting the native handler .. please fix setNativeExceptionHandler call"
50-
);
24+
export const setNativeExceptionHandler = (customErrorHandler = noop, forceApplicationToQuit = true, executeDefaultHandler = false) => {
25+
if (typeof customErrorHandler !== "function" || typeof forceApplicationToQuit !== "boolean") {
26+
console.log("setNativeExceptionHandler is called with wrong argument types.. first argument should be callback function and second argument is optional should be a boolean");
27+
console.log("Not setting the native handler .. please fix setNativeExceptionHandler call");
5128
return;
5229
}
5330
if (Platform.OS === "ios") {
54-
ReactNativeExceptionHandler.setHandlerforNativeException(
55-
executeDefaultHandler,
56-
customErrorHandler
57-
);
31+
ReactNativeExceptionHandler.setHandlerforNativeException(executeDefaultHandler, customErrorHandler);
5832
} else {
59-
ReactNativeExceptionHandler.setHandlerforNativeException(
60-
executeDefaultHandler,
61-
forceApplicationToQuit,
62-
customErrorHandler
63-
);
33+
ReactNativeExceptionHandler.setHandlerforNativeException(executeDefaultHandler, forceApplicationToQuit, customErrorHandler);
6434
}
6535
};
6636

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-exception-handler",
3-
"version": "2.8.9",
3+
"version": "2.9.0",
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)