ios - Custom NSError codes -


i building cocoa touch framework uses custom nserror object communicated errors caller. need declare enum defines custom error codes. went apple doc lists nsurlerrordomain error codes shown below:

enum {        nsurlerrorunknown = -1,       nsurlerrorcancelled = -999,       nsurlerrorbadurl = -1000,        nsurlerrortimedout = -1001,       nsurlerrorunsupportedurl = -1002,    nsurlerrorunsupportedurl = -1002,    nsurlerrorcannotconnecttohost = -1004,       nsurlerrordatalengthexceedsmaximum = -1103,       nsurlerrornetworkconnectionlost = -1005,        nsurlerrordnslookupfailed = -1006,       nsurlerrorhttptoomanyredirects = -1007,        nsurlerrorresourceunavailable = -1008,       nsurlerrornotconnectedtointernet = -1009,       nsurlerrorredirecttononexistentlocation = -1010,       nsurlerrorbadserverresponse = -1011,       nsurlerrorusercancelledauthentication = -1012,       nsurlerroruserauthenticationrequired = -1013,       nsurlerrorzerobyteresource = -1014,       nsurlerrorcannotdecoderawdata = -1015,        nsurlerrorcannotdecodecontentdata = -1016,        nsurlerrorcannotparseresponse = -1017,       nsurlerrorinternationalroamingoff = -1018,        nsurlerrorcallisactive = -1019,        nsurlerrordatanotallowed = -1020,        nsurlerrorrequestbodystreamexhausted = -1021,       nsurlerrorfiledoesnotexist = -1100,        nsurlerrorfileisdirectory = -1101,        nsurlerrornopermissionstoreadfile = -1102,        nsurlerrorsecureconnectionfailed = -1200,       nsurlerrorservercertificatehasbaddate = -1201,       nsurlerrorservercertificateuntrusted = -1202,       nsurlerrorservercertificatehasunknownroot = -1203,       nsurlerrorservercertificatenotyetvalid = -1204,      nsurlerrorclientcertificaterejected = -1205,       nsurlerrorclientcertificaterequired = -1206,       nsurlerrorcannotloadfromnetwork = -2000,        nsurlerrorcannotcreatefile= -3000,       nsurlerrorcannotopenfile = -3001,       nsurlerrorcannotclosefile = -3002,        nsurlerrorcannotwritetofile = -3003,        nsurlerrorcannotremovefile = -3004,        nsurlerrorcannotmovefile = -3005,       nsurlerrordownloaddecodingfailedmidstream = -3006,       nsurlerrordownloaddecodingfailedtocomplete = -3007     } 

q1: why apple uses negative values error codes? there specific reason that?

q2: there pattern apple follow randomize error codes?

  1. because based on return codes, 0 ok. leaves positive , negative integers. general c preference use positive integers success codes (with additional info) , negative values error codes.
  2. as can see, error codes grouped. unknown , cancelled special, 1000s http errors, 1100s access errors, 1200s connection , cert errors, 2000 network, 3000s file , stream issues.

group errors based on problem areas, , use negatives return code purposes (since returning negative interpreted error).


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -