If I get an error code result from a Cocoa function, is there any easy way to figure out what it means (other than by grepping through all the .h files in the framework bundles)?
Error Code Reference for OSX/Cocoa
For NSError errors add a line of code:
NSError *error; // ... Some code that returns an error // Get the error as a string NSString *s = [error localizedDescription]; // Observe the code for yourself or display to the user.
The sections on 'Error Domains' and 'Error Codes' in Apple's Error Handling Programming Guide address this reasonably well. You need to do the following:
Log the error, taking note of both the error domain (a human-readable / Googleable string that tells you where to look for the error code definitions) and the error code itself (an integer)
Sniff around on Google (or read from the list below) and figure out the name of the header file(s) where the error codes for that error domain are defined
Search those header file(s) for the error code you got. You should find both a constant name for the error code (like
ENOMEM), and hopefully also an explanatory comment (like
/* Cannot allocate memory */) explaining what the error means. If there's no comment, and the constant name isn't self-explanatory, just Google the constant name and you'll probably find a proper description.
Some header files of major error domains:
Error code declarations are spread across three header files:
<Foundation/FoundationErrors.h>(Generic Foundation error codes)
<AppKit/AppKitErrors.h>(Generic AppKit error codes)
<CoreData/CoreDataErrors.h>(Core Data error codes)