diff --git a/zh-cn/react-native-exception-handler.md b/zh-cn/react-native-exception-handler.md
index 33ee988d7a154ddd9439408d29857efbf57cc738..14d95cd1a7d4e478e2e5c9f284fbe274a3497f7f 100644
--- a/zh-cn/react-native-exception-handler.md
+++ b/zh-cn/react-native-exception-handler.md
@@ -1,5 +1,5 @@
-> 模板版本:v0.1.3
+> 模板版本:v0.2.2
react-native-exception-handler
@@ -47,22 +47,22 @@ To catch JS_Exceptions
```typescript
import {
- setJSExceptionHandler,
- getJSExceptionHandler,
+ setJSExceptionHandler,
+ getJSExceptionHandler,
} from "react-native-exception-handler";
// For most use cases:
// registering the error handler (maybe u can do this in the index.android.js or index.ios.js)
setJSExceptionHandler((error, isFatal) => {
- // This is your custom global error handler
- // You do stuff like show an error dialog
- // or hit google analytics to track crashes
- // or hit a custom api to inform the dev team.
+ // This is your custom global error handler
+ // You do stuff like show an error dialog
+ // or hit google analytics to track crashes
+ // or hit a custom api to inform the dev team.
});
//=================================================
// ADVANCED use case:
const exceptionhandler = (error, isFatal) => {
- // your error handler function
+ // your error handler function
};
setJSExceptionHandler(exceptionhandler, allowInDevMode);
// - exceptionhandler is the exception handler function
@@ -81,21 +81,21 @@ import { setNativeExceptionHandler } from "react-native-exception-handler";
//For most use cases:
setNativeExceptionHandler((exceptionString) => {
- // This is your custom global error handler
- // You do stuff likehit google analytics to track crashes.
- // or hit a custom api to inform the dev team.
- //NOTE: alert or showing any UI change via JS
- //WILL NOT WORK in case of NATIVE ERRORS.
+ // This is your custom global error handler
+ // You do stuff likehit google analytics to track crashes.
+ // or hit a custom api to inform the dev team.
+ //NOTE: alert or showing any UI change via JS
+ //WILL NOT WORK in case of NATIVE ERRORS.
});
//====================================================
// ADVANCED use case:
const exceptionhandler = (exceptionString) => {
- // your exception handler code here
+ // your exception handler code here
};
setNativeExceptionHandler(
- exceptionhandler,
- forceAppQuit,
- executeDefaultHandler
+ exceptionhandler,
+ forceAppQuit,
+ executeDefaultHandler
);
// - exceptionhandler is the exception handler function
// - forceAppQuit is an optional ANDROID specific parameter that defines
@@ -120,17 +120,17 @@ setNativeExceptionHandler(
1. 通过 har 包引入(在 IDE 完善相关功能后该方法会被遗弃,目前首选此方法);
2. 直接链接源码。
-方法一:通过 har 包引入
+方法一:通过 har 包引入(推荐)
> [!TIP] har 包位于三方库安装路径的 `harmony` 文件夹下。
打开 `entry/oh-package.json5`,添加以下依赖
-```diff
+```json
"dependencies": {
"@rnoh/react-native-openharmony": "file:../react_native_openharmony",
-+ "rnoh-exception-handler": "file:../../node_modules/@react-native-oh-tpl/react-native-exception-handler/harmony/exception_handler.har",
+ "@react-native-oh-tpl/react-native-exception-handler": "file:../../node_modules/@react-native-oh-tpl/react-native-exception-handler/harmony/exception_handler.har",
}
```
@@ -154,28 +154,37 @@ ohpm install
```diff
project(rnapp)
cmake_minimum_required(VERSION 3.4.1)
+set(CMAKE_SKIP_BUILD_RPATH TRUE)
set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
-set(OH_MODULE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
+set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules")
++ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp")
+set(LOG_VERBOSITY_LEVEL 1)
+set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments")
+set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie")
+set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use
+add_compile_definitions(WITH_HITRACE_SYSTRACE)
add_subdirectory("${RNOH_CPP_DIR}" ./rn)
-# RNOH_BEGIN: add_package_subdirectories
+# RNOH_BEGIN: manual_package_linking_1
add_subdirectory("../../../../sample_package/src/main/cpp" ./sample-package)
-+ add_subdirectory("${OH_MODULE_DIR}/rnoh-exception-handler/src/main/cpp" ./exception_handler)
-# RNOH_END: add_package_subdirectories
++ add_subdirectory("${OH_MODULES}/@react-native-oh-tpl/react-native-exception-handler/src/main/cpp" ./exception-handler)
+# RNOH_END: manual_package_linking_1
+
+file(GLOB GENERATED_CPP_FILES "./generated/*.cpp")
add_library(rnoh_app SHARED
+ ${GENERATED_CPP_FILES}
"./PackageProvider.cpp"
"${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp"
)
-
target_link_libraries(rnoh_app PUBLIC rnoh)
-# RNOH_BEGIN: link_packages
+# RNOH_BEGIN: manual_package_linking_2
target_link_libraries(rnoh_app PUBLIC rnoh_sample_package)
+ target_link_libraries(rnoh_app PUBLIC rnoh_exception_handler)
-# RNOH_END: link_packages
+# RNOH_END: manual_package_linking_2
```
打开 `entry/src/main/cpp/PackageProvider.cpp`,添加:
@@ -200,9 +209,8 @@ std::vector> PackageProvider::getPackages(Package::Cont
打开 `entry/src/main/ets/RNPackagesFactory.ts`,添加:
```diff
-import type {RNPackageContext, RNPackage} from 'rnoh/ts';
-import {SamplePackage} from 'rnoh-sample-package/ts';
-+ import {ExceptionHandlerPackage} from 'rnoh-exception-handler/ts';
+...
++ import {ExceptionHandlerPackage} from '@react-native-oh-tpl/react-native-exception-handler/ts';
export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
return [
@@ -217,31 +225,31 @@ export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
在 `YourProject/entry/src/main/ets/pages` 目录下,新建文件`ExceptionView.ets`
```typescript
-import { ExceptionComponent } from 'rnoh-exception-handler';
+import { ExceptionComponent } from '@react-native-oh-tpl/react-native-exception-handler';
import router from '@ohos.router';
interface RouterParam {
- errMsg: string
+ errMsg: string
}
@Entry
@Component
struct ExceptionView {
- @State errMsg: string = ''
+@State errMsg: string = ''
- aboutToAppear() {
- let params = router.getParams() as RouterParam
- this.errMsg = params.errMsg
- router.clear()
- }
-
- build() {
- Column() {
- ExceptionComponent({ errMsg: this.errMsg })
+ aboutToAppear() {
+ let params = router.getParams() as RouterParam
+ this.errMsg = params.errMsg
+ router.clear()
}
+
+ build() {
+ Column() {
+ ExceptionComponent({ errMsg: this.errMsg })
+ }
.width('100%')
- .height('100%')
- }
+ .height('100%')
+ }
}
```
@@ -266,14 +274,14 @@ import appRecovery from "@ohos.app.ability.appRecovery";
import Want from "@ohos.app.ability.Want";
export default class MyAbilityStage extends AbilityStage {
- onCreate() {
- appRecovery.enableAppRecovery();
- let want: Want = {
- bundleName: this.context.applicationInfo.name,
- abilityName: this.context.currentHapModuleInfo.mainElementName,
- };
- appRecovery.setRestartWant(want);
- }
+ onCreate() {
+ appRecovery.enableAppRecovery();
+ let want: Want = {
+ bundleName: this.context.applicationInfo.name,
+ abilityName: this.context.currentHapModuleInfo.mainElementName,
+ };
+ appRecovery.setRestartWant(want);
+ }
}
```
@@ -346,8 +354,8 @@ ohpm install
| Name | Description | Type | Required | Platform | HarmonyOS Support |
| ----------------------- | -------------------- | -------- | -------- | -------- | ----------------- |
-| `setJSExceptionHandler` | 设置 JS 异常处理方法 | function | no | All | yes |
-| `getJSExceptionHandler` | 获取 JS 异常处理方法 | function | no | All | yes |
+| `setJSExceptionHandler` | 设置 JS 异常处理方法 | function | no | Android, iOS | yes |
+| `getJSExceptionHandler` | 获取 JS 异常处理方法 | function | no | Android, iOS | yes |
## API
@@ -357,7 +365,7 @@ ohpm install
| Name | Description | Type | Required | Platform | HarmonyOS Support |
| --------------------------- | ------------------------ | -------- | -------- | -------- | ----------------- |
-| `setNativeExceptionHandler` | 设置 native 异常处理方法 | function | no | All | yes |
+| `setNativeExceptionHandler` | 设置 native 异常处理方法 | function | no | Android, iOS | yes |
## 遗留问题
@@ -368,5 +376,4 @@ ohpm install
## 开源协议
本项目基于 [The MIT License (MIT)](https://github.com/a7ul/react-native-exception-handler/blob/master/LICENSE) ,请自由地享受和参与开源。
-
-
\ No newline at end of file
+