NSError domains / custom domains - conventions and best practices

怎甘沉沦 提交于 2019-12-18 12:27:24

问题


NSError requires a domain, which I understand segments the range of error codes.

One would anticipate that there exist somewhere a registry of domain.error code but I've not been able to discover one.

Supposedly this could used for looking up localized descriptions for errors.

Does anyone have any set of known best practices for dealing with error domains and codes? An authoritative reference (major developers or framework makers) is optimal, but even blogs detailing a good convention is useful.

In your projects do you maintain registries of your error domains/codes that map to localized descriptions, recoveries, well known userinfo keys or like factories for your error objects based on domain/code?

Or do you generally just cobble together some domain and some code, and depend on well known userinfo keys such as NSLocalizedDescriptionKey, etc, in your bespoke NSError domains?


回答1:


Apple generally publishes their NS/CFError codes in a header named FrameworkNameErrors.h. For example, Foundation's error codes are in Foundation/FoundationErrors.h. In addition, they generally publish the domain and codes in their documentation for the framework.

Any independent author of a framework with its own error domain and codes should do the same.



来源:https://stackoverflow.com/questions/1779034/nserror-domains-custom-domains-conventions-and-best-practices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!