6.5. Error Handling in JNI

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:

  1. What happens to the virtual machine when native code fails?

  2. How should JNI code deal with C++ exceptions?

  3. How should JNI code deal with Java exceptions?

  4. 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.

6.5.1. Failures in Native Code

The first issue, ...

Get Component Development for the Java™ Platform now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.