Java JNI遇到分段错误时引发异常

编程入门 行业动态 更新时间:2024-10-27 14:21:32
本文介绍了Java JNI遇到分段错误时引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们有在单独的线程中运行JNI的代码.在开发过程中,有时会遇到需要调试的分段错误,但是由于代码在单独的线程中运行,因此不会报告段错误.取而代之的是,该线程实际上在没有警告的情况下就死了,从而导致调试困难.

我希望能够检测到分段错误和/或在发生段错误时引发异常,以便我们有某种迹象表明线程已经死亡而没有警告.有没有办法以这种方式检测分段错误?

解决方案

在Windows上,使用 SetUnhandledExceptionFilter 或使用__try __except构造捕获线程中的异常.在POSIX平台上,为SIGSEGV和sigaction

安装处理程序

We have code running JNI in a separate thread. We occasionally get segmentation faults while developing that we need to debug, but because the code is running in a separate thread the seg-fault isn't reported. Instead the thread essentially dies without warning making debugging difficult.

I would like to be able to either detect a segmentation fault and/or throw an exception when a seg fault occurs so that we have some indication that a thread has died without warning. Is there any way to detect segmentation faults in this manner?

解决方案

On windows, use SetUnhandledExceptionFilter or use a __try __except construct to catch exceptions in the thread. On POSIX platforms, install a handler for SIGSEGV with sigaction

更多推荐

Java JNI遇到分段错误时引发异常

本文发布于:2023-10-16 00:42:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1495967.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:异常   错误   Java   JNI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!