In a C++ project, I use the JNI invocation API to launch a JVM. I've done a little wrapper arount the JVM so I can use all the needed parts in a OO fashion. So far that works great.
Now, if the JVM does not start (JNI_CreateJavaVM
returns a value < 0) I'd like to raise an exception within my C++ code.But if I throw an exception after JNI_CreateJavaVM
, I get a buffer overrun. If I raise the exception without the JNI_CreateJavaVM
call, it works as expected.
Does anyone have a clue on what the issue could be here? Or how to debug this?
Environment: Windows, Visual Studio 2008 JDK: jrockit27.6jdk16005, but happens with SUN stock one as well
Cheers Dominik
Looks to me like you are throwing a pointer or reference to an invalid memory. It's a good idea to throw an exception by reference, but make sure that the object is not on the stack. If the object was allocated using 'new', you'll need to manage this properly (otherwise you'll have leaks). My approach is to try and throw const objects as much as possible.
Does this help?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With