Sijmen Mulder
Sijmen Mulder

Reputation: 5819

Getting bogged down by error handling in Cocoa. Am I going overboard?

Just as an example, let’s take a method for getting the App Support directory. What if NSSearchPathForDirectoriesInDomains returns no elements? What if it’s not a directory but a file? What if it couldn’t be created?

My methods are getting cluttered up not just by adding doing the checks but also from constructing the error objects, assigning error codes etc.

Upvotes: 1

Views: 81

Answers (1)

MJeffryes
MJeffryes

Reputation: 458

You probably are overdoing it. From your example, if that function is returning no elements or a file, then something is seriously wrong, and there's no way that your application can recover from it. At that point, letting the error cause a crash is the only sensible thing to do.

Upvotes: 1

Related Questions