抛出异常类_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 }

 

posted @ 2015-07-09 14:55  壬子木  阅读(329)  评论(0)    收藏  举报