Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Objective-C exception handling support #73

Open
dgelessus opened this issue Sep 17, 2017 · 0 comments
Open

Objective-C exception handling support #73

dgelessus opened this issue Sep 17, 2017 · 0 comments
Labels
enhancement New features, or improvements to existing features.

Comments

@dgelessus
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New features, or improvements to existing features.
Projects
None yet
Development

No branches or pull requests

2 participants