How can I effectively catch and handle segmentation errors with C in an OSX Carbon app?
Reference Information. I am making an OSX Carbon app. I have to call the library function from a third party. Due to problems with threads, a function can sometimes crash, usually because it is updated from one thread itself, and it gets some internally obsolete pointer or handle when I request it from another. Function is a black box for me. I want to be able to call a function, but to be able to "catch" if it crashed and provided an alternative return. On Windows, I can use the simple Visual C compiler and Intel C __try {} and __except.
__try { x=DangerousFunction(y);}
__except(EXCEPTION_EXECUTE_HANDLER) {x=0.0;}
I am trying to do the same kind of crash for OSX. I use pure C in a very large application. I call the function millions of times per second, so efficiency is also very important. (Impressive that Windows __try () overhead is immeasurably small!)
Here is what I experimented with:
1) C ++ exceptions. I'm not sure if C ++ exceptions cause segfault to fail. And my application is currently C. I can try wrappers and #ifdefs to make it C ++, but there is a lot of work for the application, and I don't think C ++ exceptions will crash.
2) + setjump + longjmp. , ... . SEGV [ !], . ( ) (SEGV). , , . , CFM BSD, , Mach Real Thing.
3) MPSetExceptionHandler. . . , segfault.