I'm a bit puzzled:
From Cocoa Programming For Mac OS X (page 63, 3rd edition, Aaron Hillegass): "If it reaches the top of the [inheritance] tree without finding a method, the function throws an exception".
From the Wikipedia article on Objective-C: "the object to which the message is directed (referred to as the receiver) is not inherently guaranteed to respond to a message, and if it doesn't it simply ignores it and returns a null pointer."
Which one is it?
When a selector is not found, it will go to -[NSObject doesNotRecognizeSelector:]. The default implementation fires off an exception.
They're both more or less correct. The difference is that the Cocoa framework defines root objects (e.g., NSObject) from which the other classes in the framework inherit; if an object doesn't respond to a message, by default it gets passed up the tree until it reaches a root object, which then throws an exception in Cocoa.
This behavior can be overridden to allow objects to do other things with messages they don't understand.
Other Objective-C frameworks can choose to deal with unrecognized messages in a different way (e.g., by returning a null pointer).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With