Getting bogged down by error handling in Cocoa. Am I going overboard?
Just as an example, let’s take a meth开发者_JAVA百科od 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.
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.
精彩评论