The usual convention is to return nil if there's an error.
If you also want to provide an error, the usual thing is to provide an extra parameter by indirection (NSError**
).
Example:
+ (id)stringWithContentsOfFile:(NSString *)path encoding:(NSStringEncoding)enc error:(NSError **)error
Return Value
A string created by reading data from the file named by path using the encoding, enc. If the file can’t be opened or there is an encoding error, returns nil.
Cocoa uses this pattern very heavily.