Rethrowing an exception via JNI ?

P

Paul J. Lucas

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
 
G

Gordon Beaton

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.

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
 

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
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top