Re: Rethrowing an exception via JNI ?



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
.



Relevant Pages

  • Re: How to test that an exception is raised ?
    ... I'm new to Python. ... > I assume you don't actually see the exception (you don't see the stack ... Do you say that it's not possible to test (using unittest) if an exception ... 2./ If I re-raise the exception, then how to not show the traceback. ...
    (comp.lang.python)
  • Re: How to test that an exception is raised ?
    ... I assume you don't actually see the exception (you don't see the stack ... Your mps2xml.mps2xml function should return a value indicating success or ... failure or should re-raise the exception. ... You should catch only IOError ...
    (comp.lang.python)
  • exception propagation for a distributed call
    ... to trap any exception that may occur, and re-raise it for the caller, ... like CORBA does. ... want to replicate a lot of code in each exception block. ...
    (comp.lang.ada)
  • Re: sufficiently pythonic code for testing type of function
    ... except AttributeError: ... Is it wrong to 're-raise' an exception with application-specific ...
    (comp.lang.python)
  • Re: How can an Exception pass over an "except" clause ?
    ... (Or can we re-raise ... an exception so that it preserves the backtrace of the "original" ... not the one that was active when you entered the except clause; it preserves the traceback. ... Either replace the inner try/except using getattr, or save the full exception details (including traceback) and use the 3-argument form of the raise statement. ...
    (comp.lang.python)