문제

As we know, many methods in JNI may cause exception and cannot be called after exception caused that may crash the JVM. We can not only use ExceptionOccurred() or ExceptionCheck() to determine whether exception occurred or not, but also can simply check something not equal to NULL or 0. Which way is the best practice?

도움이 되었습니까?

해결책

As you are only asking for "best practice", the answer is very straightforward:

  1. always call ExceptionCheck or ExceptionOccurred when calling JNI functions which may raise exceptions.
  2. 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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top