title: Catch exception in Android NDK C++ code
body: <p>I am trying to catch an error in native C++ code on Android. According to the docs FindClass returns NULL when class name cannot be find. But I got <code>FATAL EXCEPTION: main java.lang.NoClassDefFoundError: fake/class</code> and execution never reaches the if statement.                                                         </p>
  
  <pre><code>#include &lt;string.h&gt;
  #include &lt;jni.h&gt;
  
  extern "C"
  void Java_com_example_MainActivity_testError(JNIEnv *env, jobject) {
      jclass clazz = env-&gt;FindClass("fake/class");
      // never gets here
      if (clazz == NULL) {
          return;
      }
  }
  </code></pre>
  
  <p>Also this exception skips the try-catch block and crashes the app. My Java code:</p>
  
  <pre><code>static {
      System.loadLibrary("native-lib");
  }
  
  public native void testError();
  
  ...
  try {
      testError();
  } catch (Exception e) {
      // exception never get cought
  }
  </code></pre>
  
  <p>Also I use <code>cppFlags '-fexceptions'</code>. Is there a proper way to catch this exception or recover from it so the app does not crash?</p>