当前位置:网站首页>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 ");
}
边栏推荐
- Kotlin data flow - flow
- Download and installation of universal player potplayer, live stream m3u8 import
- Overview of demoplayer program framework design of ijkplayer
- You should consider upgrading via
- Echart histogram: stack histogram value formatted display
- Dart class inherits and implements mixed operators
- Uniapp (upload local pictures, preview pictures, convert Base64 format, upload audio files)
- App performance test: (III) traffic monitoring
- AI realizes "Resurrection" of relatives | old photo repair | old photo coloring, recommended by free app
- PHP redis makes high burst spike
猜你喜欢
Solution: vscode open file will always overwrite the last opened label
欧姆龙平替国产大货—JY-V640半导体晶元盒读写器
Vector control of Brushless DC motor (4): sensorless control based on sliding mode observer
JetPack - - - Navigation
Wechat applet: basic review
Custom view - extensible collapsexpendview
Echart histogram: X-axis displays value, Y-axis displays category
Echart rectangular tree diagram: simple implementation of rectangular tree diagram
电镀挂具RFID工序管理解决方案
AI实现亲人“复活”|老照片修复|老照片上色,免费APP推荐
随机推荐
Kotlin collaboration - flow+room database
【虚拟机】 VMware虚拟机占用空间过大解决
Scrcpy development environment construction and source code reading
Wechat applet (pull-down refresh data) novice to
El form form verification
Scrcpy source code walk 2 how to connect a client to a mobile server
推荐扩容工具,彻底解决C盘及其它磁盘空间不够的难题
Kotlin collaboration -- context and exception handling
【2022高考季】作为一个过来人想说的话
Kotlin collaboration - simple use of collaboration
Kotlin collaboration - start and cancel, scope
线程池学习
Echart histogram: echart implements stacked histogram
Wechat applet: basic review
Detailed explanation of Yanghui triangle
JetPack - - -WorkManger
Recommend a capacity expansion tool to completely solve the problem of insufficient disk space in Disk C and other disks
‘ipconfig‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件。
MFS详解(五)——MFS元数据日志服务器安装与配置
High burst solution 2