Let me first say that I have very limited knowledge in Objective C programming.
I have a C executable that calls an user-defined function written in Objective C.
Provided that anything could happen in the user code, what would be the best way to safely wrap the code so that the C function returns gracefuly ?
In a C++ wrapper, I would write a function try-catching all exceptions to prevent the C++ exception from propagating into the C code, where the behaviour is not defined by the C standard.
I suppose that I should first prevent any ObjC exception from crossing the language boundaries (i.e. propagate into the C code), so I would write a wrapper like:
void objc_wrap(void) {
@try {
obj_entry();
}
@catch (NSException *ex) {
// handle NSException
}
@catch (...) {
// handle the rest
}
}
However, my limited knowledge of the language does not tell me if there are other mechanisms that would make the user code cross the module boundary and cause undefined exception.
Furthermore, is any initialization/cleanup of the Objective C runtime needed before calling the user function, provided that the entry point is pure C?
Note: Signals and exit() need not be handled, as the wrapper is run in a forked process.