Factored try-catch inside JNI macros.