JNA should include std::exception::what() in thrown `java.lang.Error`
还没有人认领这个 Issue。
评估
调研方向
从 Native.loadLibrary 绑定路径开始,跟踪原生 std::exception 如何变成 java.lang.Error。将该路径与 issue 中的 InvocationMapper 和 GetLastError workaround 进行比较。完成标准是,抛出的错误包含 std::exception::what(),而不是只报告无效内存访问,并且已根据 Windows 示例检查其行为。
由索引模型根据 Issue 内容生成。
描述
As a caller of a cpp hunk of math I want std::exceptions to be nicely translated by JNA across the bindings so that I can more easily debug runtime problems.
I have some cpp code that I've updated to throw std::exception's that contain valuable data in their what() clause. What I was hoping JNA would do is this:
//mylib.dll
#include <exception>
extern "C" __declspec(dllexport)
const void MYCOMPANY_compute_eigen_values_or_something()
{
throw std::exception("message from native code: kablamo!")
}
interface MyLib: Library {
public void MYCOMPANY_compute_eigen_values_or_something()
}
var lib = Native.loadLibrary("mylib", MyLib.class, options)
try { lib.MYCOMPANY_compute_eigen_values_or_something() }
catch(Throwable ex){
System.out.println(ex)
}
expected: java.lang.Error: In native code: message from native code: kablamo!
actual: java.lang.Error: Invalid memory access
... on: Windows 10 1903, JNA 4.2.2
My work around:
Wrap my code in a try { } catch { }, save it to a global variable, and expose a function GetLastError() that I then call from the handler. If you combine this with StackWalker you can even get a java--ish native code stack trace in your preconditions/postconditions. From the java side, I add my own InvocationMapper to catch JNA thrown java.lang.Errors, call GetLastError() then throw a new exception with the results.
- 主要语言
- Java
- 星标
- 8.9k
- 派生
- 1.7k
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
java-native-access/jna 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 88/100
java-native-access/jna#1740 ·
-
难度 4/5 3-5 天 新手友好度 66/100
java-native-access/jna#1738 ·
-
难度 4/5 3-5 天 新手友好度 45/100
java-native-access/jna#1736 ·
-
难度 3/5 1-2 天 新手友好度 65/100
java-native-access/jna#1717 ·
-
Windows32Exception - The parameter is incorrect可能重新可做 @marktech0813 于 330 天前认领,目前没有进行中的 PR。 未关闭
难度 4/5 3-5 天 新手友好度 35/100
java-native-access/jna#1700 · 11 条评论 ·
查看 java-native-access/jna 的全部 Issue
相似的 Issue
-
waiting-for-triage
难度 1/5 1 小时以内 新手友好度 72/100
spring-cloud/spring-cloud-openfeign#1443 ·
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 84/100
ADORSYS-GIS/keycloak-oid4vp-plugin#221 ·
维护者通常 2 天内回复
-
status: team-only type: dependency-upgrade
难度 2/5 1-3 小时 新手友好度 65/100
spring-projects/spring-boot#52099 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 67/100
tchiotludo/akhq#3307 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
objectionary/jeo-maven-plugin#1885 ·
维护者通常 4 天内回复