1

I have an Android application that I'm writing, and it uses a module that runs on the JNI layer. I have no control or knowledge on how the NDK module works, and it sometimes throws an un-handled exception, and my app crashes.

Is there any way to catch those JNI propagating exceptions in the Java layer? Or at least detect when the DNK is going to crash due to an exception?

  • Does this answer your question? [Catch exception in Android NDK C++ code](https://stackoverflow.com/questions/40096235/catch-exception-in-android-ndk-c-code) – Armaggheddon Aug 20 '21 at 13:19
  • The JNI documentation says "Java exceptions left unhandled are propagated back to the VM.", so you can just use a try-catch block. However, I think your native code is trying to do JNI operations *while an exception is signaled*. It should call `ExceptionClear` or stop trying to perform JNI operations instead. – Botje Aug 23 '21 at 09:24

0 Answers0