Skip to content

Commit

Permalink
Merge pull request #67 from thunkable/call-existing-native-handler
Browse files Browse the repository at this point in the history
Save and call pre-existing native handler on Android
  • Loading branch information
a7ul authored Jun 21, 2018
2 parents f9175d2 + 9f60307 commit 40d2dee
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class ReactNativeExceptionHandlerModule extends ReactContextBaseJavaModul
private Activity activity;
private static Class errorIntentTargetClass = DefaultErrorScreen.class;
private Callback callbackHolder;
private Thread.UncaughtExceptionHandler originalHandler;

public ReactNativeExceptionHandlerModule(ReactApplicationContext reactContext) {
super(reactContext);
Expand All @@ -30,6 +31,7 @@ public String getName() {
@ReactMethod
public void setHandlerforNativeException(final boolean forceToQuit, Callback customHandler){
callbackHolder = customHandler;
originalHandler = Thread.getDefaultUncaughtExceptionHandler();

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

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


if (originalHandler != null) {
originalHandler.uncaughtException(thread, throwable);
}

if (forceToQuit) {
System.exit(0);
}
Expand Down

0 comments on commit 40d2dee

Please sign in to comment.