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

Ask A Question

Stats

  • Questions 205k
  • Answers 205k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Take a look at the mutable property of the class… May 12, 2026 at 9:01 pm
  • Editorial Team
    Editorial Team added an answer Windows 2003 had 2 sessions + 1 console session, Windows… May 12, 2026 at 9:01 pm
  • Editorial Team
    Editorial Team added an answer It's pretty simple: types defined in implementation only are only… May 12, 2026 at 9:01 pm

Related Questions

Update: clarified question (I hope) Hi. I'm developing a plugin in Wordpress and I'm
This may be a doozy, but does anyone have an idea how to: Pass
I want to share my experience of using maven through a proxy. You would
I erroneously delete all the rows from a MS SQL 2000 table that is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.