Reputation: 8033
Most to all of the classes in Objective-C returns nil if passed nil or some error, but NSURL
throws an exception. Specifically, the method [NSURL fileURLWithPath]
.
It is documented: "Passing nil for this parameter produces an exception."
But, can anyone explain Apple would throw an exception instead of returning nil?
Upvotes: 5
Views: 233
Reputation: 8033
Here is Apple's docs or error handling:
exceptions are used solely for programmer errors
Upvotes: 0
Reputation: 53000
It is calling a method on nil
that is allowed. Many methods can throw exceptions if given an invalid argument. For example see NSMutableArray
's addObject:
.
Upvotes: 1