Skip to content

Commit 40d2dee

Browse files
authored
Merge pull request #67 from thunkable/call-existing-native-handler
Save and call pre-existing native handler on Android
2 parents f9175d2 + 9f60307 commit 40d2dee

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class ReactNativeExceptionHandlerModule extends ReactContextBaseJavaModul
1515
private Activity activity;
1616
private static Class errorIntentTargetClass = DefaultErrorScreen.class;
1717
private Callback callbackHolder;
18+
private Thread.UncaughtExceptionHandler originalHandler;
1819

1920
public ReactNativeExceptionHandlerModule(ReactApplicationContext reactContext) {
2021
super(reactContext);
@@ -30,6 +31,7 @@ public String getName() {
3031
@ReactMethod
3132
public void setHandlerforNativeException(final boolean forceToQuit, Callback customHandler){
3233
callbackHolder = customHandler;
34+
originalHandler = Thread.getDefaultUncaughtExceptionHandler();
3335

3436
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
3537
@Override
@@ -47,7 +49,11 @@ public void uncaughtException(Thread thread, Throwable throwable) {
4749

4850
activity.startActivity(i);
4951
activity.finish();
50-
52+
53+
if (originalHandler != null) {
54+
originalHandler.uncaughtException(thread, throwable);
55+
}
56+
5157
if (forceToQuit) {
5258
System.exit(0);
5359
}

0 commit comments

Comments
 (0)