JNA捕捉异常 [英] JNA Catching Exceptions
问题描述
当我在底层本机代码中抛出一个异常时,JNA得到一个无效内存访问错误。我假设这是因为C库不能通过它的堆栈抛出一个异常(实际上是C ++ / CLR但有C导出)?那么没有什么真正的方式来报告Java的异常?或者应该工作,我只是在做一些令人难以置信的错误的事情?
DllExport void Initialize(char * dir)
{
throw gcnew System :: Exception(Testing);
}
Java可以检测到这些抛出的异常,我想我实际上可以看看将内存指针传递到我所有的C导出中,并检查它们是否为空,但是似乎是一个迂回的方式。
您需要自己处理c ++异常,而是构建可以传递给代码的java端的java异常。
I have a quick question about dealing with exceptions being thrown by libraries under JNA...
When I throw an exception in the underlying native code, JNA gets a invalid memory access error. I'm assuming this is because C libraries cannot throw an exception up through it's stack (it's actually C++/CLR but has C exports)? So is there no real way to report the exception to Java? Or "should it work" and I'm just doing something incredibly wrong?
DllExport void Initialize(char* dir)
{
throw gcnew System::Exception("Testing");
}
It would be nice for Java to be able to detect these thrown exceptions, and I guess I could actually look into passing a memory pointer into all my C exports and check to see if those are null or not, but seems like a roundabout way.
You need to handle the c++ exception yourself and instead build a java exception which can be passed to the java side of the code.
这篇关于JNA捕捉异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!