-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
Improve error handling when a required selector isn't defined #94
Comments
Hm. I agree that a hard crash in response to a missing method isn't great, but I'm not sure what a better alternative would be. I don't think it would be a good idea to continue execution normally after a missing method is called. If the caller expected a return value from the missing method, it will now get random garbage. Even if no return value was expected, the method call was meant to have some effect, which was probably required for the following code to work correctly. In any case, the following code will be working with unexpected or garbage data, and is likely to error or segfault (or silently do the wrong thing, which is even worse). A safer approach would be to let the exception be thrown, but catch it in Rubicon to prevent Python from crashing entirely. However, catching Objective-C exceptions from Python is not easily possible, see #73. An easier alternative is setting an uncaught exception handler using Somewhat related: in #69 I suggested adding checks to ensure that custom ObjC subclasses implement all methods of protocols they implement. That would prevent "unrecognized selector" errors from incomplete implementations of protocols. I don't think that would help with the example posted here - that looks more like a type error. |
I wasn't suggesting a completely silent failure, or even preventing the hard crash - just transforming it into a Python hard crash. Turning an Objective C stack trace caused by a missing selector into a Python |
If what you're looking for is a Python traceback to where the crash happened, then the
Our test suite already uses this. Converting the error to a Python exception sadly isn't easily done. It's not possible to use So in the end I think we're still left with catching the Objective-C exception. As explained in #73, that is annoying to implement, requires compiled code (since |
At present, if a class doesn't implement a required selector, the Objective C runtime raises a hard crash. For example:
It should be possible to avoid the hard crash by implementing
doesNotRecognizeSelector:
on the base ObjInstance. This should provide a better opportunity to manage or report the crash than showing a memory dump.The text was updated successfully, but these errors were encountered: