Problems throwing from C Native Code

B

Bill Medland

Can anyone tell me why this isn't working?

I am using JNI and trying to throw an exception that has more arguments
than a single string, so I can't use ThrowNew. However when I use
Throw the compiler complains "error: structure has no member named
`longjmp'".

Below is the code, based on some untested code back in 2002 in this
group.
Note that Throw takes a jthrowable rather than a jobject. I don't
know; can we simpy cast? I presume not. Then how do I generate a
jthrowable?

Presumably it is possible to throw a reasonable exception from native C
code.

---
/* myThrowGenericError
*
* Throw the given generic error for unhandled conditions
*/
extern void myThrowGenericError(JNIEnv *env, const char *domain, int
value, const char *context) {
/* Bother. Not quite!!! */
/* Throwing exceptions with more complex constructors is not well
documented.
* The source for this is a conversation on
comp.lang.java.programmer entitled "JNI Exceptions", dated approx 16
October 2002 between Michael Grammling and Gordon Beaton,
* message id [email protected]
*/
jclass cls;
jmethodID mid;
jstring jsDomain;
jstring jsContext;
jobject exception;

if ((cls = (*env)->FindClass(env, "A4wapiGenericError")) == 0 ||
(mid = (*env)->GetMethodID(env, cls, "<init>",
"Ljava/lang/String;i;Ljava/lang/String")) == 0 ||
(jsDomain = (*env)->NewStringUTF(env, domain)) == 0 ||
(jsContext = (*env)->NewStringUTF(env, context)) == 0 ||
(exception = (*env)->NewObject(env, cls, mid, jsDomain, (jint)
value, jsContext)) == 0 ||
//1) {
((*env)->Throw(env, exception)) != 0) {
errlogAdd(ERRLOG_ERROR, "Java Native Interface error - unable
to generate generic error (domain %s) value=%d (context:%s)", domain,
value, context);
}
}
 
B

Bill Medland

Bill said:
Can anyone tell me why this isn't working?

I am using JNI and trying to throw an exception that has more arguments
than a single string, so I can't use ThrowNew. However when I use
Throw the compiler complains "error: structure has no member named
`longjmp'".

Name clash - Because the other headers needed to support the rest of
the module included a macro for Throw

Apologies
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top