4

I'm looking for a way to catch an exception that was thrown on the Android (JAVA) side and handle it on the Native side.

What i need to do is to detect the type of exception and handle it accordingly.

Any idea how it's done ?

refaelos
  • 7,927
  • 7
  • 36
  • 55

1 Answers1

5

I figured it out...

if(jEnv->ExceptionCheck() == JNI_TRUE ) {
  __android_log_write(ANDROID_LOG_DEBUG, "JNI", "HAS EXCEPTION"); 
  jthrowable exceptionObj = jEnv->ExceptionOccurred();

  jclass exceptionClass = cocos2d::JniHelper::getClassID("com/companyName/example/exceptions/MyException", jEnv);
  if (jEnv->IsInstanceOf(exceptionObj, exceptionClass)) {
    __android_log_write(ANDROID_LOG_DEBUG, "JNI", "Cought MyException!"); 

    throw MyException();
  }
}
Brent
  • 4,153
  • 4
  • 30
  • 63
refaelos
  • 7,927
  • 7
  • 36
  • 55