我想知道在~JniFloatArray
投掷时是否dataArray
被com/emcjpn/sleep/SleepAlgorithmBreakException
调用了吗?
JNIEXPORT jobject JNICALL Java_com_emcjpn_sleep_SleepAlgorithm_nativePushNewDataAndCalculate(JNIEnv *env, jclass type,
jlong ptr, jfloatArray data_) {
JniFloatArray dataArray(data_, env);
jfloat *data = dataArray.getData();
SleepAlgorithm* algorithm = (SleepAlgorithm*)ptr;
jsize length = dataArray.length();
SleepAlgorithmResult result = algorithm->pushNewDataAndCalculate(data, data + length);
if (result.shouldBreak) {
jclass exception = env->FindClass("com/emcjpn/sleep/SleepAlgorithmBreakException");
env->ThrowNew(exception, "sleep calculation failed, invalid ecg data");
return NULL;
}
/*Some other code*/
}
答案 0 :(得分:2)
是。在JNI文档中很难找到,但env->ThrowNew
实际上并没有立即抛出异常。相反,它会进行设置,以便在您返回Java-land时抛出异常。
这意味着你必须跟随ThrowNew
返回某种类型(返回Java-land),并且该返回将导致所有析构函数运行。