Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public String getName() {
public void setHandlerforNativeException(
final boolean executeOriginalUncaughtExceptionHandler,
final boolean forceToQuit,
Callback customHandler) {
final boolean disableNativeErrorScreen,
Callback customHandler
) {

callbackHolder = customHandler;
originalHandler = Thread.getDefaultUncaughtExceptionHandler();
Expand All @@ -47,18 +49,20 @@ public void uncaughtException(Thread thread, Throwable throwable) {
String stackTraceString = Log.getStackTraceString(throwable);
callbackHolder.invoke(stackTraceString);

if (nativeExceptionHandler != null) {
nativeExceptionHandler.handleNativeException(thread, throwable, originalHandler);
} else {
activity = getCurrentActivity();
if (nativeExceptionHandler != null) {
nativeExceptionHandler.handleNativeException(thread, throwable, originalHandler);
} else {
if (!disableNativeErrorScreen) {
activity = getCurrentActivity();

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

activity.startActivity(i);
activity.finish();
activity.startActivity(i);
activity.finish();
}

if (executeOriginalUncaughtExceptionHandler && originalHandler != null) {
originalHandler.uncaughtException(thread, throwable);
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ declare const setNativeExceptionHandler: (
handler: NativeExceptionHandler,
forceAppQuit?: boolean, // Android only
executeDefaultHandler?: boolean,
disableNativeErrorScreen?: boolean // Android only
) => void;
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const setJSExceptionHandler = (customHandler = noop, allowedInDevMode = f

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

export const setNativeExceptionHandler = (customErrorHandler = noop, forceApplicationToQuit = true, executeDefaultHandler = false) => {
export const setNativeExceptionHandler = (customErrorHandler = noop, forceApplicationToQuit = true, executeDefaultHandler = false, disableNativeErrorScreen = false) => {
if (typeof customErrorHandler !== "function" || typeof forceApplicationToQuit !== "boolean") {
console.log("setNativeExceptionHandler is called with wrong argument types.. first argument should be callback function and second argument is optional should be a boolean");
console.log("Not setting the native handler .. please fix setNativeExceptionHandler call");
Expand All @@ -34,7 +34,12 @@ export const setNativeExceptionHandler = (customErrorHandler = noop, forceApplic
if (Platform.OS === "ios") {
ReactNativeExceptionHandler.setHandlerforNativeException(executeDefaultHandler, customErrorHandler);
} else {
ReactNativeExceptionHandler.setHandlerforNativeException(executeDefaultHandler, forceApplicationToQuit, customErrorHandler);
ReactNativeExceptionHandler.setHandlerforNativeException(
executeDefaultHandler,
forceApplicationToQuit,
disableNativeErrorScreen,
customErrorHandler
);
}
};

Expand Down