Handling JNI Exceptions

In ILE RPG, an exception causes an exception message to be signaled. Programs do not need to check explicitly for exceptions; instead, you can code exception handlers to get control when an exception occurs. You only have to handle JNI exceptions yourself when you are making your own JNI calls. When a call to a JNI function results in an unhandled Java™ exception, there is no accompanying exception message. Instead, the JNI programmer must check whether an exception occurred after each call to a JNI function. This is done by calling the ExceptionOccurred JNI function, which returns a Java Exception object (or the Java null object which has a value of 0 in the JNI). Once you have determined that an exception has occurred, the only JNI calls you can make are ExceptionClear and ExceptionDescribe. After you have called ExceptionClear, you are free to make JNI calls again. If you make a non-exception JNI call before calling ExceptionClear, the exception will disappear, and you will not be able to get any further details. RPG always converts a JNI exception into an RPG exception (it signals one of the RNX030x messages, depending on the RPG function that was being done at the time).

Tip!

You may want to include this type of exception-handling code in your versions of the JNI wrapper procedures above.



[ Top of Page | Previous Page | Next Page | Contents | Index ]