title: How do I get an error message when failing to load a JVM via JNI?
body: <p>I would like to retrieve an error message that explains why the jvm failed to load. From the examples provided here:</p>
  
  <p><a href="http://java.sun.com/docs/books/jni/html/invoke.html" rel="nofollow noreferrer">http://java.sun.com/docs/books/jni/html/invoke.html</a></p>
  
  <p>I extracted this example:</p>
  
  <pre><code> /* Create the Java VM */
   res = JNI_CreateJavaVM(&amp;jvm, (void**)&amp;env, &amp;vm_args);
  
   if (res &lt; 0) {
       // retrieve verbose error here?
       fprintf(stderr, "Can't create Java VM\n");
       exit(1);
   }
  </code></pre>
  
  <p>In my specific case I'm providing invalid arguments in the vm_args and would expect to see  what I get on the command line: "Unrecognized option: -foo=bar"</p>
  
  <p>On further testing it looks like the jvm is putting the message I want to stdout or stderr. I believe I would need to capture stdout and stderr to get the error I'm looking for (unless of course there is a simpler way). I'm coding in C++ so if someone can show a way to capture the error into a stringstream that would be ideal.</p>
  
  <p>Thanks,
  Randy</p>