In my Java code I create MyException class (extending Exception class)
with the getCustomCode() method.
In my C++ code, when I call a Java method that throws MyException I
need to execute the getCustomCode of this exception to properly handle
the exception.
To accomplish that I execute the Java method that throws MyException
with this code:
---
jint result = env->CallIntMethodA(javaObj, methodId, params);
----
Right after this line I check for JavaException with this code:
---
jthrowable exc = env->ExceptionOccurred();
if(exc)
{
jclass objCls = env->FindClass("com/mycompany/myapp/exception/
MyException");
jmethodID codeMethod = env->GetMethodID(objCls, "getCustomCode",
"()I");
if(!objCls || !codeMethod){ ........ }
// Try to execute getCustomCode java method.
jint codeResult = env->CallIntMethod((jobject)exc, codeMethod);
...
...
}
---
But, when I try to execute the getCustomCode through JNI it fails. I
did some checks with the JNI methods IsAssignableFrom and IsInstanceOf
and the result was:
---
jclass objCls = env->FindClass ("com/mycompany/myapp/exception/
MyException");
jclass objThrowable = env->FindClass ("java/lang/Throwable");
if(env->IsAssignableFrom(objCls, objThrowable) == JNI_TRUE) { /* TRUE!
*/ }
---
The condition returned true, so my class is correct. Another check:
---
jclass objCls = env->FindClass ("com/mycompany/myapp/exception/
MyException");
jclass objThrowable = env->FindClass ("java/lang/Throwable");
if(env->IsInstanceOf((jobject)exc, objCls) == JNI_TRUE) { /* FALSE
*/ }
if(env->IsInstanceOf((jobject)exc, objThrowable) == JNI_TRUE) { /*
FALSE */ }
---
Both conditions returned false, so neither MyException nor Throwable
is the exc class!
So, what is the jthrowable object? And how can I cast the jthrowable
object to a jobject to access MyException members? Is it possible?
Thank you!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en