You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This one is a bit tricky. On all modern architectures, Objective-C exceptions are implemented using libunwind, the same system as C++ exceptions. Unfortunately it's not possible to handle these exceptions using only ctypes. We would need a small C helper function, something like bool callAndCatchException(void *(*func)(void *), void **outRetval, id *outException) that calls the function pointer, catches any exception that comes out, and reports success/failure as well as the return value or exception.
The other question is how we should expose Objective-C exceptions on the Python side. Should we route every Objective-C method call through our helper function, and automatically wrap any Objective-C exceptions in Python exceptions? Or should we provide an extra function to allow the user to do this on demand? I would be in favor of the latter option, because using callAndCatchException adds extra overhead even when no exceptions are caught (not just the call, but also the creation of the wrapper func). There's also not that much benefit in converting Objective-C exceptions to Python exceptions if they won't be handled anyway - in fact it's probably more useful not to convert them, to get a proper crash report with the native stack trace and debugging info.
The text was updated successfully, but these errors were encountered:
This one is a bit tricky. On all modern architectures, Objective-C exceptions are implemented using libunwind, the same system as C++ exceptions. Unfortunately it's not possible to handle these exceptions using only
ctypes
. We would need a small C helper function, something likebool callAndCatchException(void *(*func)(void *), void **outRetval, id *outException)
that calls the function pointer, catches any exception that comes out, and reports success/failure as well as the return value or exception.The other question is how we should expose Objective-C exceptions on the Python side. Should we route every Objective-C method call through our helper function, and automatically wrap any Objective-C exceptions in Python exceptions? Or should we provide an extra function to allow the user to do this on demand? I would be in favor of the latter option, because using
callAndCatchException
adds extra overhead even when no exceptions are caught (not just the call, but also the creation of the wrapperfunc
). There's also not that much benefit in converting Objective-C exceptions to Python exceptions if they won't be handled anyway - in fact it's probably more useful not to convert them, to get a proper crash report with the native stack trace and debugging info.The text was updated successfully, but these errors were encountered: