Java – JNA catch exception

I have a quick question about handling exceptions thrown by the Library under JNA

JNA receives an invalid memory access error when I throw an exception in the underlying native code I assume this is because the C library cannot throw an exception through its stack (it is actually C / C + + LR but has C output)? So is there a real way to report Java exceptions? Or "it should work", I just made some incredible mistakes?

DllExport void Initialize(char* dir)
{
    throw gcnew System::Exception("Testing");
}

It would be nice for Java to detect these thrown exceptions. I think I can actually consider passing memory pointers to all my C exports and checking whether they are null, but it looks like a circuitous way

Solution

You need to handle C exceptions yourself, but build a Java exception that can be passed to the Java side of the code

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>