# ArkTs使用JSVM-API接口进行错误处理开发 ### 介绍 使用JSVM-API接口进行错误处理开发,使得在JSVM-API模块中能够更好地管理和响应错误情况。通过合理使用这些函数,可以提高模块的稳定性和可靠性。 该工程中展示的代码详细描述可查如下链接: - [使用JSVM-API接口进行错误处理开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-error.md) ### 效果预览 | 首页 | 执行及结果即时反馈 | | :-----------------------------------------------------------: | :-----------------------------------------------------------: | | | | ### 使用说明 1. 在主界面,可以点击Hello World,开始执行。 2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 ### 工程目录 ``` createerror/src/ ├── main │ ├── cpp │ │ ├── types │ │ │ ├── libentry │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 │ │ ├── CMakeLists.txt // 配置CMake打包参数 │ │ ├── hello.cpp // 实现Native侧的runTest接口 │ ├── ets │ │ ├── entryability │ │ ├── entrybackupability │ │ ├── pages │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 │ ├── module.json5 │ └── resources ├── ohosTest │ ├── ets │ │ ├── test │ │ ├── Ability.test.ets // 自动化测试代码 createrangeerror/src/ ├── main │ ├── cpp │ │ ├── types │ │ │ ├── libcreaterangeerror │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 │ │ ├── CMakeLists.txt // 配置CMake打包参数 │ │ ├── hello.cpp // 实现Native侧的runTest接口 │ ├── ets │ │ ├── createrangeerrorability │ │ ├── pages │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 │ ├── module.json5 │ └── resources ├── ohosTest │ ├── ets │ │ ├── test │ │ ├── Ability.test.ets // 自动化测试代码 createsyntaxerror/src/ ├── main │ ├── cpp │ │ ├── types │ │ │ ├── libcreatesyntaxerror │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 │ │ ├── CMakeLists.txt // 配置CMake打包参数 │ │ ├── hello.cpp // 实现Native侧的runTest接 │ ├── ets │ │ ├── createsyntaxerrorability │ │ ├── pages │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 │ ├── module.json5 │ └── resources ├── ohosTest │ ├── ets │ │ ├── test │ │ ├── Ability.test.ets // 自动化测试代码 createtypeerror/src/ ├── main │ ├── cpp │ │ ├── types │ │ │ ├── libcreatetypeerror │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 │ │ ├── CMakeLists.txt // 配置CMake打包参数 │ │ ├── hello.cpp // 实现Native侧的runTest接 │ ├── ets │ │ ├── createtypeerrorability │ │ ├── entrybackupability │ │ ├── pages │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 │ ├── module.json5 │ └── resources ├── ohosTest │ ├── ets │ │ ├── test │ │ ├── Ability.test.ets // 自动化测试代码 getandclearlastexception/src/ ├── main │ ├── cpp │ │ ├── types │ │ │ ├── libgetandclearlastexception │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 │ │ ├── CMakeLists.txt // 配置CMake打包参数 │ │ ├── hello.cpp // 实现Native侧的runTest接 │ ├── ets │ │ ├── getandclearlastexceptionability │ │ ├── pages │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 │ ├── module.json5 │ └── resources ├── ohosTest │ ├── ets │ │ ├── test │ │ ├── Ability.test.ets // 自动化测试代码 getlasterrorinfo/src/ ├── main │ ├── cpp │ │ ├── types │ │ │ ├── libgetlasterrorinfo │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 │ │ ├── CMakeLists.txt // 配置CMake打包参数 │ │ ├── hello.cpp // 实现Native侧的runTest接 │ ├── ets │ │ ├── getlasterrorinfoability │ │ ├── pages │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 │ ├── module.json5 │ └── resources ├── ohosTest │ ├── ets │ │ ├── test │ │ ├── Ability.test.ets // 自动化测试代码 iserror/src/ ├── main │ ├── cpp │ │ ├── types │ │ │ ├── libiserror │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 │ │ ├── CMakeLists.txt // 配置CMake打包参数 │ │ ├── hello.cpp // 实现Native侧的runTest接 │ ├── ets │ │ ├── iserrorability │ │ ├── pages │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 │ ├── module.json5 │ └── resources ├── ohosTest │ ├── ets │ │ ├── test │ │ ├── Ability.test.ets // 自动化测试代码 isexceptionpending/src/ ├── main │ ├── cpp │ │ ├── types │ │ │ ├── libisexceptionpending │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 │ │ ├── CMakeLists.txt // 配置CMake打包参数 │ │ ├── hello.cpp // 实现Native侧的runTest接 │ ├── ets │ │ ├── isexceptionpendingability │ │ ├── pages │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 │ ├── module.json5 │ └── resources ├── ohosTest │ ├── ets │ │ ├── test │ │ ├── Ability.test.ets // 自动化测试代码 throwerror/src/ ├── main │ ├── cpp │ │ ├── types │ │ │ ├── libthrowerror │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 │ │ ├── CMakeLists.txt // 配置CMake打包参数 │ │ ├── hello.cpp // 实现Native侧的runTest接 │ ├── ets │ │ ├── throwerrorability │ │ ├── pages │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 │ ├── module.json5 │ └── resources ├── ohosTest │ ├── ets │ │ ├── test │ │ ├── Ability.test.ets // 自动化测试代码 throwrangeerror/src/ ├── main │ ├── cpp │ │ ├── types │ │ │ ├── libthrowrangeerror │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 │ │ ├── CMakeLists.txt // 配置CMake打包参数 │ │ ├── hello.cpp // 实现Native侧的runTest接 │ ├── ets │ │ ├── throwrangeerrorability │ │ ├── pages │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 │ ├── module.json5 │ └── resources ├── ohosTest │ ├── ets │ │ ├── test │ │ ├── Ability.test.ets // 自动化测试代码 throwsyntaxerror/src/ ├── main │ ├── cpp │ │ ├── types │ │ │ ├── libthrowsyntaxerror │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 │ │ ├── CMakeLists.txt // 配置CMake打包参数 │ │ ├── hello.cpp // 实现Native侧的runTest接 │ ├── ets │ │ ├── throwsyntaxerrorability │ │ ├── pages │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 │ ├── module.json5 │ └── resources ├── ohosTest │ ├── ets │ │ ├── test │ │ ├── Ability.test.ets // 自动化测试代码 throwtypeerror/src/ ├── main │ ├── cpp │ │ ├── types │ │ │ ├── libthrowtypeerror │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 │ │ ├── CMakeLists.txt // 配置CMake打包参数 │ │ ├── hello.cpp // 实现Native侧的runTest接 │ ├── ets │ │ ├── throwtypeerrorability │ │ ├── pages │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 │ ├── module.json5 │ └── resources ├── ohosTest │ ├── ets │ │ ├── test │ │ ├── Ability.test.ets // 自动化测试代码 ``` ### 相关权限 不涉及。 ### 依赖 不涉及。 ### 约束与限制 1.本示例仅支持标准系统上运行, 支持设备:Phone。 2.本示例为Stage模型,支持API15版本SDK,版本号:5.0.3.135,镜像版本号:HarmonyOS NEXT_5.0.3.135。 3.本示例需要使用DevEco Studio 5.0.3 Release (Build Version: 5.0.9.300, built on March 13, 2025)及以上版本才可编译运行。 ### 下载 如需单独下载本工程,执行如下命令: ``` git init git config core.sparsecheckout true echo code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError > .git/info/sparse-checkout git remote add origin https://gitee.com/openharmony/applications_app_samples.git git pull origin master ```