Re: Rethrowing an exception via JNI ?
- From: Gordon Beaton <not@xxxxxxxxx>
- Date: 30 Nov 2005 09:01:32 +0200
On Wed, 30 Nov 2005 03:49:41 GMT, Paul J. Lucas wrote:
> 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
--
[ 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
.
- References:
- Rethrowing an exception via JNI ?
- From: Paul J. Lucas
- Rethrowing an exception via JNI ?
- Prev by Date: Old books on Java, still good?
- Next by Date: Re: Can't find my own exception class via JNI
- Previous by thread: Rethrowing an exception via JNI ?
- Next by thread: Can't find my own exception class via JNI
- Index(es):
Relevant Pages
|