title: How to get the message from a Java exception caught in JNI
body: <p>I am attempting to catch exceptions being thrown by Java and report the exception message to my own logging framework. However, if I do this, there's an obvious chicken-and-egg problem; I'm trying to get the message using the Java <code>getMessage()</code> call:</p>
  
  <pre><code>jthrowable e = env-&gt;ExceptionOccurred();
  jclass clazz = env-&gt;GetObjectClass(e);
  jmethodID getMessage = env-&gt;GetMethodID(clazz,
                                          "getMessage",
                                          "()Ljava/lang/String;");
  </code></pre>
  
  <p>but I can't actually resolve getMessage, because the pending exception causes the JVM to abort when I call <code>GetObjectClass</code>.</p>
  
  <p>Is there a safe way to get the <code>jmethodID</code> for all exceptions up-front? If I Just get the method ID for <code>Throwable.getMessage()</code> at application startup, will that <code>jmethodID</code> be portable to other classes?  Or is the appropriate approach to call <code>env-&gt;ExceptionClear()</code> and just keep on using the same local jthrowable reference?</p>