Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2006

Tip: Looking for answers? Try searching our database.

Problems throwing from C Native Code

Thread view: 
Bill Medland - 26 Jun 2006 18:11 GMT
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 aokeom$njr$1@news.rm.uni-karlsruhe.de
    */
   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);
   }
}
Bill Medland - 26 Jun 2006 18:27 GMT
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.