如何在Android App中捕获所有React Native异常?

时间:2016-10-19 09:25:49

标签: android react-native react-native-android

在React Native源代码DevSupportManagerImpl.java中有以下代码:

  @Override
  public void handleException(Exception e) {
      if (mIsDevSupportEnabled) {
          if (e instanceof JSException) {
              FLog.e(ReactConstants.TAG, "Exception in native call from JS", e);
              // TODO #11638796: convert the stack into something useful
              showNewError(e.getMessage() + "\n\n" + ((JSException) e).getStack(), new StackFrame[] {},
                 JSEXCEPTION_ERROR_COOKIE, ErrorType.JS);
          } else {
              showNewJavaError(e.getMessage(), e);
          }
      } else {
          mDefaultNativeModuleCallExceptionHandler.handleException(e);
      }
  }

当mIsDevSupportEnabled为false(发布版本)时,如何捕获java代码中的异常?

1 个答案:

答案 0 :(得分:0)

我认为应该使用Crashlytics。为了更好地理解,请检查github中的以下对话

Handling React Native Exceptions