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