12
12
13
13
public class ReactNativeExceptionHandlerModule extends ReactContextBaseJavaModule {
14
14
15
- private ReactApplicationContext reactContext ;
15
+ private ReactApplicationContext reactContext ;
16
16
private Activity activity ;
17
17
private static Class errorIntentTargetClass = DefaultErrorScreen .class ;
18
18
private static NativeExceptionHandlerIfc nativeExceptionHandler ;
19
19
private Callback callbackHolder ;
20
20
private Thread .UncaughtExceptionHandler originalHandler ;
21
21
22
22
public ReactNativeExceptionHandlerModule (ReactApplicationContext reactContext ) {
23
- super (reactContext );
24
- this .reactContext = reactContext ;
25
- }
23
+ super (reactContext );
24
+ this .reactContext = reactContext ;
25
+ }
26
26
27
- @ Override
28
- public String getName () {
29
- return "ReactNativeExceptionHandler" ;
30
- }
27
+ @ Override
28
+ public String getName () {
29
+ return "ReactNativeExceptionHandler" ;
30
+ }
31
31
32
32
33
- @ ReactMethod
34
- public void setHandlerforNativeException (
35
- final boolean executeOriginalUncaughtExceptionHandler ,
36
- final boolean forceToQuit ,
37
- Callback customHandler ) {
33
+ @ ReactMethod
34
+ public void setHandlerforNativeException (
35
+ final boolean executeOriginalUncaughtExceptionHandler ,
36
+ final boolean forceToQuit ,
37
+ Callback customHandler ) {
38
38
39
- callbackHolder = customHandler ;
40
- originalHandler = Thread .getDefaultUncaughtExceptionHandler ();
39
+ callbackHolder = customHandler ;
40
+ originalHandler = Thread .getDefaultUncaughtExceptionHandler ();
41
41
42
- Thread .setDefaultUncaughtExceptionHandler (new Thread .UncaughtExceptionHandler () {
42
+ Thread .setDefaultUncaughtExceptionHandler (new Thread .UncaughtExceptionHandler () {
43
43
44
- @ Override
45
- public void uncaughtException (Thread thread , Throwable throwable ) {
44
+ @ Override
45
+ public void uncaughtException (Thread thread , Throwable throwable ) {
46
46
47
- String stackTraceString = Log .getStackTraceString (throwable );
48
- callbackHolder .invoke (stackTraceString );
47
+ String stackTraceString = Log .getStackTraceString (throwable );
48
+ callbackHolder .invoke (stackTraceString );
49
49
50
- if (executeOriginalUncaughtExceptionHandler && originalHandler != null ) {
51
- originalHandler .uncaughtException (thread , throwable );
52
- }
50
+ if (nativeExceptionHandler != null ) {
51
+ nativeExceptionHandler .handleNativeException (thread , throwable , originalHandler );
52
+ } else {
53
+ activity = getCurrentActivity ();
53
54
54
- if ( nativeExceptionHandler != null ) {
55
- nativeExceptionHandler . handleNativeException ( thread , throwable );
56
- } else {
57
- activity = getCurrentActivity ( );
55
+ Intent i = new Intent ();
56
+ i . setClass ( activity , errorIntentTargetClass );
57
+ i . putExtra ( "stack_trace_string" , stackTraceString );
58
+ i . setFlags ( Intent . FLAG_ACTIVITY_NEW_TASK );
58
59
59
- Intent i = new Intent ();
60
- i .setClass (activity , errorIntentTargetClass );
61
- i .putExtra ("stack_trace_string" ,stackTraceString );
62
- i .setFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
60
+ activity .startActivity (i );
61
+ activity .finish ();
63
62
64
- activity .startActivity (i );
65
- activity .finish ();
63
+ if (executeOriginalUncaughtExceptionHandler && originalHandler != null ) {
64
+ originalHandler .uncaughtException (thread , throwable );
65
+ }
66
66
67
- if (forceToQuit ) {
68
- System .exit (0 );
69
- }
67
+ if (forceToQuit ) {
68
+ System .exit (0 );
69
+ }
70
+ }
71
+ }
72
+ });
73
+ }
70
74
71
- }
72
- }
73
- });
74
- }
75
-
76
- public static void replaceErrorScreenActivityClass (Class errorScreenActivityClass ){
77
- errorIntentTargetClass = errorScreenActivityClass ;
78
- }
75
+ public static void replaceErrorScreenActivityClass (Class errorScreenActivityClass ){
76
+ errorIntentTargetClass = errorScreenActivityClass ;
77
+ }
79
78
80
79
public static void setNativeExceptionHandler (NativeExceptionHandlerIfc nativeExceptionHandler ) {
81
80
ReactNativeExceptionHandlerModule .nativeExceptionHandler = nativeExceptionHandler ;
82
81
}
83
- }
82
+ }
0 commit comments