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