I've google'd around a bit, and haven't really found a good answer for my question: What is the customary way to pass back error information to java from native jni code?
I would normally just pick a design and go with it, but this code is called every 5 milliseconds, (approx), so I thought I'd ask if there's a customary 'clean / efficient' way to do this.
The way I see it, I have four obvious options:
On each call, in java create an "error return" object and pass it through to the JNI. If there's a problem, the native code fills in the error description in this object, and the java code checks it on return. Since errors are not the common case, this creates a lot of objects for the GC to clean up, and 99.99% of them are unnecessary.
Similar to #1, create some single "error return" object in the java class which is passed to each method call over and over. Check it in the java code on each return for errors. This seems dodgy to me, but maybe it's the proper option?
Create an object in the native code which contains a description of the error if applicable, and pass it back as a return value to java. After the call in java, check the return for null. This seems less wasteful than #1, but it seems a bit awkward.
Simply build a integer return value on the jni method, and pass back an int corresponding to the "exit" value of the native code. Enumerate all possible native exit states in a java map. Compare the return value to '0', and look up the error in this map if necessary. This appears more efficient than the others, but seems more clumsy, since a change in native code would require someone to go back and update the "error table".
I feel as though I'm missing something obvious... is there a guru out there that can offer any insight?
Thanks!