Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explain why NSURL throws errors on nil

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?

like image 823
Michael Ozeryansky Avatar asked Nov 10 '22 07:11

Michael Ozeryansky


1 Answers

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:.

like image 192
CRD Avatar answered Nov 15 '22 05:11

CRD



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!