Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 191529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:20:57+00:00 2026-05-11T16:20:57+00:00

I would like to retrieve an error message that explains why the jvm failed

  • 0

I would like to retrieve an error message that explains why the jvm failed to load. From the examples provided here:

http://java.sun.com/docs/books/jni/html/invoke.html

I extracted this example:

 /* Create the Java VM */
 res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);

 if (res < 0) {
     // retrieve verbose error here?
     fprintf(stderr, "Can't create Java VM\n");
     exit(1);
 }

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”

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.

Thanks,
Randy

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:20:57+00:00Added an answer on May 11, 2026 at 4:20 pm

    I was able to get what I needed by using the "vfprintf" option described here:

    https://web.archive.org/web/20111229234347/http://java.sun.com/products/jdk/faq/jnifaq-old.html

    although I used the jdk1.2 options. This code snippet summarizes my solution:

    static string jniErrors;
    
    static jint JNICALL my_vfprintf(FILE *fp, const char *format, va_list args)
    {
        char buf[1024];
        vsnprintf(buf, sizeof(buf), format, args);
        jniErrors += buf;
        return 0;
    }
    
    ...
    
    JavaVMOption options[1];
    options[0].optionString = "vfprintf";
    options[0].extraInfo = my_vfprintf;
    
    JavaVMInitArgs vm_args;
    memset(&vm_args, 0, sizeof(vm_args));
    vm_args.nOptions = 1;
    vm_args.options = options;
    vm_args.version = JNI_VERSION_1_4;
    vm_args.ignoreUnrecognized = JNI_FALSE;
    
    JNIEnv env;
    JavaVM jvm;
    
    jint res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
    
    if (res != JNI_OK)
        setError(jniErrors);
    
    jniErrors.clear();
    

    Also interesting was that I could not for the life of me capture stdout or stderr correctly with any of the freopen or dup2 tricks. I could load my own dll and redirect correctly but not the jvm. Anyway, it’s better this way because I wanted the errors in memory rather than in a file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to retrieve the ethernet address of the network interface that is
I would like to retrieve at runtime the values for the dialect and connection.driver_class
I have a reference to a type, for which I would like to retrieve
I have a 3-leveled hierarchy of entities: Customer-Order-Line, which I would like to retrieve
I would like to write an simple application able to retrieve some certain data
I'm using the Spring class FreeMarkerConfigurationFactoryBean to retrieve FreeMarker templates. I would like these
I would like to construct a search query that groups the records by their
Would like to get a list of advantages and disadvantages of using Stored Procedures.
Would like to create a strong password in C++. Any suggestions? I assume it
I would like to test a string containing a path to a file for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.