As you are only asking for "best practice", the answer is very straightforward:
- always call
ExceptionCheck
orExceptionOccurred
when calling JNI functions which may raise exceptions. - always check return values from JNI functions
Calling ExceptionOccurred
after each JNI call, preferably in a dedicated function, allows you to get some information on the exception, for logging, and also allows you to call ExceptionClear
.
Make the dedicated function return void, and use the return values from the JNI functions to distinguish between normal and error paths.