Search code examples
iphoneobjective-ciosnsexception

throwing an exception in an objective-c method when a required input parameter is nil?


Noting the general guidance re use of exceptions in objective-c (e.g. throwing an exception in objective-c/cocoa) I'm still not quite sure for this case:

is throwing an exception in an objective-c method when a required input parameter is nil best practice/ok?

If no, what approach would be typical then here in objective-c?


Solution

  • That would be a valid exception, or even an assert (which in turn will throw an exception). there is the NSParameterAssert macro defined already that will do what you want.