开发者

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

开发者 https://www.devze.com 2023-03-05 19:29 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消