When two programming platforms meet, you have to deal with all the idiosyncrasies of both. In JNI, this is most obvious when you are dealing with errors and failures. There are at least four distinct issues to consider:
What happens to the virtual machine when native code fails?
How should JNI code deal with C++ exceptions?
How should JNI code deal with Java exceptions?
How should JNI code communicate errors back to the VM?
The answer to each of these questions stems from a single principle: Well-written JNI code should preserve the appearance of Java, even when native code fails. In other words, problems should only reach the virtual machine in the form of Java exceptions.
The first issue, ...