42 |
#include <stdio.h> |
#include <stdio.h> |
43 |
#include <jcl.h> |
#include <jcl.h> |
44 |
|
|
|
static char errstr[4098]; // this way the memory is pre-allocated, so that we do not have to worry if we are out of memory. |
|
|
|
|
45 |
JNIEXPORT void JNICALL JCL_ThrowException(JNIEnv * env, char * className, char * errMsg) { |
JNIEXPORT void JNICALL JCL_ThrowException(JNIEnv * env, char * className, char * errMsg) { |
46 |
jclass excClass; |
jclass excClass; |
47 |
if((*env)->ExceptionOccurred(env)) { |
if((*env)->ExceptionOccurred(env)) { |
54 |
if(errExcClass == NULL) { |
if(errExcClass == NULL) { |
55 |
errExcClass = (*env)->FindClass(env, "java/lang/InternalError"); |
errExcClass = (*env)->FindClass(env, "java/lang/InternalError"); |
56 |
if(errExcClass == NULL) { |
if(errExcClass == NULL) { |
57 |
sprintf(errstr,"JCL: Utterly failed to throw exeption %s with message %s.",className,errMsg); |
fprintf(stderr, "JCL: Utterly failed to throw exeption "); |
58 |
fprintf(stderr, errstr); |
fprintf(stderr, className); |
59 |
|
fprintf(stderr, " with message "); |
60 |
|
fprintf(stderr, errMsg); |
61 |
return; |
return; |
62 |
} |
} |
63 |
} |
} |
64 |
sprintf(errstr,"JCL: Failed to throw exception %s with message %s: could not find exception class.", className, errMsg); |
/* Removed this (more comprehensive) error string to avoid the need for a |
65 |
(*env)->ThrowNew(env, errExcClass, errstr); |
* static variable or allocation of a buffer for this message in this (unlikely) |
66 |
|
* error case. --Fridi. |
67 |
|
* |
68 |
|
* sprintf(errstr,"JCL: Failed to throw exception %s with message %s: could not find exception class.", className, errMsg); |
69 |
|
*/ |
70 |
|
(*env)->ThrowNew(env, errExcClass, className); |
71 |
} |
} |
72 |
(*env)->ThrowNew(env, excClass, errMsg); |
(*env)->ThrowNew(env, excClass, errMsg); |
73 |
} |
} |