抛出异常类_ThrowException
common.h
1 #pragma once 2 3 #include <jni.h> 4 5 /** 6 * Throws a new exception using the given exception class 7 * and exception message. 8 * 9 * @param env JNIEnv interface. 10 * @param className class name. 11 * @param message exception message. 12 */ 13 void ThrowException( 14 JNIEnv* env, 15 const char* className, 16 const char* message 17 );
common.cpp
1 #include "Common.h" 2 3 void ThrowException( 4 JNIEnv* env, 5 const char* className, 6 const char* message) 7 { 8 // Get the exception class 9 jclass clazz = env->FindClass(className); 10 11 // If exception class is found 12 if (0 != clazz) 13 { 14 // Throw exception 15 env->ThrowNew(clazz, message); 16 17 // Release local class reference 18 env->DeleteLocalRef(clazz); 19 } 20 }

浙公网安备 33010602011771号