
package com.masteratul.exceptionhandler;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Callback;

public class ReactNativeExceptionHandlerModule extends ReactContextBaseJavaModule {

  private ReactApplicationContext reactContext;
    private Activity activity;
    private static Class errorIntentTargetClass = DefaultErrorScreen.class;
    private Callback callbackHolder;

    public ReactNativeExceptionHandlerModule(ReactApplicationContext reactContext) {
    super(reactContext);
    this.reactContext = reactContext;
  }

  @Override
  public String getName() {
    return "ReactNativeExceptionHandler";
  }


  @ReactMethod
  public void setHandlerforNativeException(Callback customHandler, final boolean forceToQuit){
      this.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);
            
              if (BuildConfig.DEBUG) {
                  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);
              activity.finish();
            
              if (forceToQuit) {
                System.exit(0);
              }
          }
      });
  }

   public static void replaceErrorScreenActivityClass(Class errorScreenActivityClass){
       errorIntentTargetClass = errorScreenActivityClass;
   }
}

@@ -965,21 +965,16 @@
 %7B%0A      
-this.
 callback
@@ -1378,64 +1378,8 @@
     
-%0A              if (BuildConfig.DEBUG) %7B%0A                
   Lo
@@ -1409,31 +1409,16 @@
 tring);%0A
-              %7D
 %0A       

Revert the old code