JVM crashes while executing native code (DLL) [message #531489] |
Wed, 05 May 2010 04:36  |
Eclipse User |
|
|
|
Hi.
I have a DLL with C++ code, which execute native code for launching XSLT transformations. Besides, that DLL also executes code for invokin g other scripting language for other application based in COM.
My problem is that sometimes, when that code native is executed, the Java Virtual Machine raise a fatal error and crashes. I have tried to use the exception system of JNI but it doesn't work. I mean, it seems that the DLL try to access a forbbiden memmory zone or something like that.
Because of the control while DLL is executing is out of JVM, I don't know how could I catch that error...
Do you think that executing the native code in a especific thread (not in the main therad) will be useful to avoid the crash?
In other case, is there any method for showing a Message Dialog before the crash?
Have you got any suggestions about this issue?
Thanks in advance.
Regards,
Carlos.
|
|
|
Re: JVM crashes while executing native code (DLL) [message #531849 is a reply to message #531489] |
Thu, 06 May 2010 07:41  |
Eclipse User |
|
|
|
Hi.
The solution consists firstable in catching the C++ exception with a try-catch block like the next:
try{
.....
.....
}catch(_com_error &e) {
printf("Error : %s\n",
(const char*)_bstr_t(e.Description()));
return -1;
}
Later on, there has to use the JNI exception system for throwing the C exception and let the Java Virtual Machine catch it. The next C++ code let the JNI method throw a exception which will be understood by JVM.
jclass newExcCls;
newExcCls = (*env).FindClass("java/lang/Exception");
(*env).ThrowNew(newExcCls, "Thrown from C++ code");
The class which load the DLL into the JVM must declare the native JNI method the exception that will throw.
Best regards,
Carlos.
|
|
|
Powered by
FUDForum. Page generated in 0.02743 seconds