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 / November 2005

Tip: Looking for answers? Try searching our database.

Rethrowing an exception via JNI ?

Thread view: 
Paul J. Lucas - 30 Nov 2005 03:49 GMT
    What's the proper way to rethrow an exception in JNI?

        int result = env->CallIntMethod(
           obj, methID, arg
        );
        if ( jthrowable t = env->ExceptionOccurred() ) {
           env->ExceptionClear(); // should this be called here?
           env->Throw( t );       // what about this?
        }

    The JNI documetation I've seen doesn't talk about this.  If all
    one wants to to is "notice" the exception (but not really
    "catch" it), what does one do?  I don't really want to "catch"
    it, just pass it back to the Java side.

    - Paul
Gordon Beaton - 30 Nov 2005 07:01 GMT
>     What's the proper way to rethrow an exception in JNI?
>
[quoted text clipped - 10 lines]
>     "catch" it), what does one do?  I don't really want to "catch"
>     it, just pass it back to the Java side.

If you do ExceptionClear(), you need to use Throw(t) to re-raise the
exception just like in your example.

If you just want to notice the exception, then don't clear it and it
stays active (and you don't need to re-throw it). Note though that you
aren't allowed to do much of anything with the JVM while the exception
is active.

Some information at the bottom of this page:
http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/design.html

Note that ExceptionDescribe() might also clear the exception:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4067541

/gordon

Signature

[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e



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.