catchthrow.c

来自「jni java本地接口编程例子原代码,是java调用本地操作系统代码的接口」· C语言 代码 · 共 33 行

C
33
字号
#include <stdio.h>#include <jni.h>#include "CatchThrow.h"JNIEXPORT void JNICALL Java_CatchThrow_doit(JNIEnv *env, jobject obj){    jthrowable exc;    jclass cls = (*env)->GetObjectClass(env, obj);    jmethodID mid =         (*env)->GetMethodID(env, cls, "callback", "()V");    if (mid == NULL) {        return;    }    (*env)->CallVoidMethod(env, obj, mid);    exc = (*env)->ExceptionOccurred(env);    if (exc) {        /* We don't do much with the exception, except that         * we print a debug message for it, clear it, and          * throw a new exception. */        jclass newExcCls;        (*env)->ExceptionDescribe(env);        (*env)->ExceptionClear(env);        newExcCls = (*env)->FindClass(env,                       "java/lang/IllegalArgumentException");        if (newExcCls == NULL) {            /* Unable to find the exception class, give up. */            return;        }        (*env)->ThrowNew(env, newExcCls, "thrown from C code");    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?