我们有在单独的线程中运行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遇到分段错误时引发异常
发布评论