Hm, this might be a little controversial.
At the moment the two methods
+instancesRespondToSelector: and -respondsToSelector:
will raise an exception when passed a NULL selector.
I prefer that it returns NO in these circumstances.
First, let me confess that I do not know the behaviour on other systems.
But in as a general rule I think that querying methods like:
Is the system to be able to do XXX?
Should never throw an exception. The answer is either YES or NO.
I think exceptions should be throw when during a request like:
Count number of lines in file with name "YYY"
some error occur.
The difference is that in the second case the error interrupts
the normal flow of events. While in the first case
it does not add anything except for extra code to catch
the potential exception.
Wim Oudshoorn.
ChangeLog
---------
2003-02-15 Willem Rein Oudshoorn <[EMAIL PROTECTED]>
* Source/NSObject.m ([NSObject +instancesRespondToSelector:]): return NO for
null selector
instead of raising an exception
([NSObject -respondsToSelector:]): return NO for null selector instead of
raising an exception
*** ../../core/base/Source/NSObject.m Sun Jan 26 20:38:42 2003
--- Source/NSObject.m Sat Feb 15 10:29:23 2003
***************
*** 1124,1141 ****
* where a subclass implements -forwardInvocation: to respond to
* selectors not normally handled ... in these cases the subclass
* may override this method to handle it.
- * <br />Raises NSInvalidArgumentException if given a null selector.
*/
+ (BOOL) instancesRespondToSelector: (SEL)aSelector
{
if (aSelector == 0)
! [NSException raise: NSInvalidArgumentException
! format: @"%@ null selector given", NSStringFromSelector(_cmd)];
! #if 0
! return (class_get_instance_method(self, aSelector) != METHOD_NULL);
! #else
! return __objc_responds_to((id)&self, aSelector);
! #endif
}
/**
--- 1124,1140 ----
* where a subclass implements -forwardInvocation: to respond to
* selectors not normally handled ... in these cases the subclass
* may override this method to handle it.
*/
+ (BOOL) instancesRespondToSelector: (SEL)aSelector
{
if (aSelector == 0)
! {
! return NO;
! }
! else
! {
! return __objc_responds_to((id)&self, aSelector);
! }
}
/**
***************
*** 1659,1673 ****
* where a subclass implements -forwardInvocation: to respond to
* selectors not normally handled ... in these cases the subclass
* may override this method to handle it.
- * <br />Raises NSInvalidArgumentException if given a null selector.
*/
- (BOOL) respondsToSelector: (SEL)aSelector
{
if (aSelector == 0)
! [NSException raise: NSInvalidArgumentException
! format: @"%@ null selector given", NSStringFromSelector(_cmd)];
!
! return __objc_responds_to(self, aSelector);
}
/**
--- 1658,1674 ----
* where a subclass implements -forwardInvocation: to respond to
* selectors not normally handled ... in these cases the subclass
* may override this method to handle it.
*/
- (BOOL) respondsToSelector: (SEL)aSelector
{
if (aSelector == 0)
! {
! return NO;
! }
! else
! {
! return __objc_responds_to(self, aSelector);
! }
}
/**
_______________________________________________
Bug-gnustep mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/bug-gnustep