I’m trying to access the message in a jthrowable while handing an exception generated when I fail to find a class. However, I am unable to access the message ID of getMessage() on the jthrowable object, and I don’t know why. I’ve tried changing the signature of getMessage to ‘()Ljava/lang/String’ (without the semicolon at the end, but that’s necessary, right?) with no joy. I’m confused as hell about this. I even tried replacing getMessage with toString, and that didn’t work. Obviously I’m doing something trivially wrong here.
Here’s the code I’m using:
jthrowable java_exception; jclass java_class; jmethodID method; java_exception = (*jEnv)->ExceptionOccurred(jEnv); assert (java_exception != NULL); java_class = (*jEnv)->GetObjectClass (jEnv, java_exception); assert (java_class != NULL); method = (*jEnv)->GetMethodID (jEnv, java_class, 'getMessage', '()Ljava/lang/String;'); if (method == NULL) { printf ('Seriously, how do I get here?!\n'); (*jEnv)->ExceptionDescribe (jEnv); return; }
The output of this code (amongst other things) looks like this:
Seriously, how do I get here?!
Exception in thread ‘main’ java.lang.NoClassDefFoundError: com/planet/core360/docgen/Processor
javap -p -s java.lang.Throwable gives me this:
Compiled from ‘Throwable.java’
public class java.lang.Throwable extends java.lang.Object implements java.io.Serializable{
…
public java.lang.String getMessage();
Signature: ()Ljava/lang/String;
…
Okay, so it looks like my problem was that
GetObjectClassdoesn’t act the way you’d expect it to on a jthrowable, or at least the results of it are not useful for the purposes of getting methods. Replacing that portion of the code with this works:Damnably odd, that. I hope this helps someone else in the future, though.