Changeset 1423 for trunk/bindings
- Timestamp:
- 12/02/10 14:22:56 (2 years ago)
- File:
-
- 1 edited
-
trunk/bindings/java/native/NexusFile.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bindings/java/native/NexusFile.c
r1421 r1423 59 59 60 60 static jclass nexusException; // Global variable 61 static jmethodID nexusExceptionConstructor; // Global variable61 static JavaVM *jvm; // Global variable 62 62 63 63 JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { … … 68 68 assert(ret == JNI_OK); 69 69 70 // Find the class and store the method ID 71 // Will use the class loader that loaded the JNI library 70 // Find and store the NexusException class for use in JapiError 72 71 nexusException = (*env)->FindClass(env,"org/nexusformat/NexusException"); 73 72 assert(nexusException); 74 73 75 nexusExceptionConstructor = (*env)->GetMethodID(env, nexusException, "<init>","(Ljava/lang/String;)V"); 76 assert(nexusExceptionConstructor); 74 jvm = vm; 77 75 78 76 return JNI_VERSION_1_1; … … 82 80 ERROR TREATMENT 83 81 84 The NAPI writes any errors to stdout through a special function. 85 This is not very feasible in a Java environment where an exception should 86 be thrown. Fortunately it is possible to define an own error processing 87 function to be used for error processing. This error handling function 88 is defined here. A NexusException is constructed and thrown. 82 The NAPI posts any errors to a customisable function. 83 We construct and throw a NexusException with the message received. 89 84 --------------------------------------------------------------------------*/ 90 static void JapiError(void *pData, char *text) 91 { 92 JNIEnv *env = (JNIEnv *)pData; 93 jobject exception; 94 jstring jtext; 95 char *args[2]; 85 static void JapiError(void *pData, char *text) { 86 // better ignore the env passed in via pData, it is unsafe due to #219 87 JNIEnv *env; 96 88 97 89 #ifdef DEBUG … … 99 91 #endif 100 92 93 (*jvm)->AttachCurrentThread (jvm, (void **) &env, NULL); 94 101 95 if (env == NULL) { 102 // if there is no tthread environment we do not need to throw an exception96 // if there is no thread environment we do not need to throw an exception 103 97 return; 104 98 } 105 99 106 jtext = (*env)->NewStringUTF(env,text); 107 args[0] = (char *)jtext; 108 args[1] = 0; 109 exception = (*env)->NewObjectA(env, nexusException, nexusExceptionConstructor, (jvalue *) args); 110 (*env)->Throw(env, exception); 111 100 (*env)->ThrowNew(env, nexusException, text); 112 101 } 113 102
Note: See TracChangeset
for help on using the changeset viewer.
