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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.