当前位置:网站首页>JNI exception handling
JNI exception handling
2022-06-13 06:32:00 【Road and distance】
JNI exception handling
C++ Exception handling
- 1. Customize struct overwrite exception The method inside
- 2.throw Throw custom type exception ,catch post-processing
try {
// c++ Exception handling ,
// 1. Override inheritance exception Methods , Throw a custom exception class
// 2.throw Custom exception (string,int etc. ),catch post-processing
int a = 10;
int b = 0;
if (b == 0) {
// throw "b is zero";
throw NoZeroException();
}
int c = a / b;
}
catch (NoZeroException e) {
__android_log_print(ANDROID_LOG_INFO, "JNI_TAG", "exception ---> %s", e.what());
}
catch (const char *message) {
__android_log_print(ANDROID_LOG_INFO, "JNI_TAG", "exception ---> %s", message);
}
JNI exception handling
- 1.native Layer handles
- 2. Throw a java Class Throwable object , Give Way java Layer handles
jclass jclz = env->GetObjectClass(thiz);
jfieldID f_id = env->GetFieldID(jclz, "name", "Ljava/lang/String;");
// Check whether there is abnormality
bool error = env->ExceptionCheck();
if (error) {
__android_log_print(ANDROID_LOG_INFO, "JNI_TAG", "exception ---> Something went wrong ");
// Clear exceptions
env->ExceptionClear();
// 1.native Layer handles
// 2. Throw a java Class Throwable object , Give Way java Layer handles
jclass no_such_method = env->FindClass("java/lang/NoSuchFieldException");
env->ThrowNew(no_such_method,"NoSuchFieldException name");
}
java Layer handles
public native void jniException();
// java Layer handling exception
try{
jniException();
}catch (Exception e){
//e.printStackTrace();
Log.i("JNI_TAG"," abnormal ");
}
边栏推荐
- Hbuilderx: installation of hbuilderx and its common plug-ins
- 【案例】一个超级好用的工具 —— 给程序员用的计算器
- MFS explanation (VI) -- MFS chunk server installation and configuration
- SSM框架整合--->简单后台管理
- Applet export (use) public function, public data
- Uni app disable native navigation bar
- Learning records countless questions (JS)
- App performance test: (II) CPU
- 动态链接库嵌套样例
- Intelligent digital asset management helps enterprises win the post epidemic Era
猜你喜欢

【新手上路常见问答】关于技术管理

Recommend a capacity expansion tool to completely solve the problem of insufficient disk space in Disk C and other disks

App performance test: (III) traffic monitoring

RN Metro packaging process and sentry code monitoring

Jetpack - basic use of room

Solutions to common problems in small program development
![[virtual machine] VMware virtual machine occupies too much space. Solution](/img/3d/bca30c6e6f7fa8400a077ed0a29e16.png)
[virtual machine] VMware virtual machine occupies too much space. Solution

Analysis of 43 cases of MATLAB neural network: Chapter 10 classification of discrete Hopfield Neural Network -- evaluation of scientific research ability of colleges and Universities

Wechat applet (get location)

Dragon Boat Festival wellbeing, use blessing words to generate word cloud
随机推荐
Applet export (use) public function, public data
Wechat applet (pull-down refresh data) novice to
Fichier local second Search Tool everything
JetPack - - -WorkManger
PHP redis makes high burst spike
Scrcpy development environment construction and source code reading
Omron Ping replaces the large domestic product jy-v640 semiconductor wafer box reader
MFS详解(七)——MFS客户端与web监控安装配置
[JS] array de duplication
JVM基础
线程相关点
Kotlin collaboration - start and cancel, scope
App performance test: (IV) power
Huawei developer certification and deveco studio compiler Download
Kotlin collaboration - simple use of collaboration
[2022 college entrance examination season] what I want to say as a passer-by
The jadx decompiler can decompile jars and apks
本地文件秒搜工具 Everything
Explication détaillée du triangle Yang hui
Logcat -b events and eventlogtags print the location correspondence of the events log in the code