|
22 | 22 | #include "jni_Errors.h"
|
23 | 23 | #include "jni_Globals.h"
|
24 | 24 |
|
25 |
| -void ThrowFatalError(const char *message) { |
| 25 | +void jni_ThrowFatalError(JNIEnv *env, const char *message) { |
26 | 26 | #ifdef USE_DEBUG
|
27 | 27 | fprintf(stderr, "Fatal Error: %s\n", message);
|
28 | 28 | #endif
|
29 | 29 |
|
30 |
| - JNIEnv *env = NULL; |
31 |
| - if ((*jvm)->GetEnv(jvm, (void **)(&env), jni_version) == JNI_OK) { |
32 |
| - (*env)->FatalError(env, message); |
33 |
| - } |
| 30 | + (*env)->FatalError(env, message); |
34 | 31 |
|
35 | 32 | exit(EXIT_FAILURE);
|
36 | 33 | }
|
37 | 34 |
|
38 |
| -void ThrowException(const char *classname, const char *message) { |
39 |
| - JNIEnv *env = NULL; |
40 |
| - if ((*jvm)->GetEnv(jvm, (void **)(&env), jni_version) == JNI_OK) { |
41 |
| - // Locate our exception class. |
42 |
| - // FIXME This needs to be relocated to a jni_Global. |
43 |
| - jclass Exception_class = (*env)->FindClass(env, classname); |
| 35 | +void jni_ThrowException(JNIEnv *env, const char *classname, const char *message) { |
| 36 | + // Locate our exception class. |
| 37 | + // FIXME This needs to be relocated to a jni_Global. |
| 38 | + jclass Exception_class = (*env)->FindClass(env, classname); |
| 39 | + |
| 40 | + if (Exception_class != NULL) { |
| 41 | + (*env)->ThrowNew(env, Exception_class, message); |
| 42 | + #ifdef USE_DEBUG |
| 43 | + fprintf(stderr, "%s: %s\n", classname, message); |
| 44 | + #endif |
| 45 | + (*env)->DeleteLocalRef(env, Exception_class); |
| 46 | + } |
| 47 | + else { |
| 48 | + Exception_class = (*env)->FindClass(env, java_lang_NoClassDefFoundError); |
44 | 49 |
|
45 | 50 | if (Exception_class != NULL) {
|
46 |
| - (*env)->ThrowNew(env, Exception_class, message); |
47 | 51 | #ifdef USE_DEBUG
|
48 |
| - fprintf(stderr, "ThrowException(): %s: %s\n", classname, message); |
| 52 | + fprintf(stderr, "%s: %s\n", java_lang_NoClassDefFoundError, classname); |
49 | 53 | #endif
|
| 54 | + |
| 55 | + (*env)->ThrowNew(env, Exception_class, classname); |
50 | 56 | (*env)->DeleteLocalRef(env, Exception_class);
|
51 | 57 | }
|
52 | 58 | else {
|
53 |
| - Exception_class = (*env)->FindClass(env, java_lang_NoClassDefFoundError); |
54 |
| - |
55 |
| - if (Exception_class != NULL) { |
56 |
| - #ifdef USE_DEBUG |
57 |
| - fprintf(stderr, "ThrowException(): %s: %s\n", java_lang_NoClassDefFoundError, classname); |
58 |
| - #endif |
59 |
| - |
60 |
| - (*env)->ThrowNew(env, Exception_class, classname); |
61 |
| - (*env)->DeleteLocalRef(env, Exception_class); |
62 |
| - } |
63 |
| - else { |
64 |
| - // Unable to find exception class, Terminate with error. |
65 |
| - ThrowFatalError("Unable to locate exception class."); |
66 |
| - } |
| 59 | + // Unable to find exception class, Terminate with error. |
| 60 | + jni_ThrowFatalError(env, "Unable to locate exception class."); |
67 | 61 | }
|
68 | 62 | }
|
69 | 63 | }
|
0 commit comments