O'Reilly logo

Component Development for the Java™ Platform by Stuart Dabbs Halloway

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required