简体   繁体   English

如何使用 JNA 处理 Fortran RTL 错误?

[英]How to handle Fortran RTL error with JNA?

I'm running a shared library (compiled with Intel) using JNA.我正在使用 JNA 运行一个共享库(由 Intel 编译)。 In rare cases the Fortran-call ends with a forrtl: severe code.在极少数情况下,Fortran 调用以forrtl: severe代码结束。 Something like就像是

forrtl: severe (408): fort: (3): Subscript #1 of the array IWU has value 0 which is less than the lower bound of 1

Is there a way to "catch" this runtime error using JNA?有没有办法使用 JNA 来“捕获”这个运行时错误?

There is no general mechanism for passing error codes from native code to JNA.没有将错误代码从本机代码传递到 JNA 的通用机制。 At best, JNA will know the function failed from its return value.充其量,JNA 会从其返回值中知道 function 失败。

However, if the native code provides a means of reading those error codes (eg, the Windows GetLastError() function, or the global errno variable on Linux and macOS), then more specific details can be retrieved.但是,如果本机代码提供读取这些错误代码的方法(例如,Windows GetLastError() function,或 Linux 和 macOS 上的全局errno变量),则可以检索更具体的详细信息。

For an Intel Fortran "severe" error, program execution stops unless it's handled on the native side, so I don't think there's anything you can do to "catch" it in JNA unless it's already "caught" in the library you're using... in which case, you just need to properly react to the failed method call.对于 Intel Fortran“严重”错误,程序执行将停止,除非它在本机端处理,所以我认为你无法在 JNA 中“捕获”它,除非它已经在你正在使用的库中“捕获” using... 在这种情况下,您只需要对失败的方法调用做出正确的反应。 The Fortran source can be modified to catch some runtime errors (such as in I/O , dynamic memory management or image control) and return this status.可以修改 Fortran 源以捕获一些运行时错误(例如在I/O 、动态 memory 管理或图像控制中)并返回此状态。 However, for this particular array bounds error of the question, this may not apply.但是,对于这个问题的特定数组边界错误,这可能不适用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM