NSError
is a class and it is used as the preferred way to handle errors in objective-c. Usually it works like this:
You declare a NSError
pointer and sends the address to that one in as a parameter to a method that might fail. If something goes wrong in the method a NSError
object is created and populated with info about the error and when the methods returns you can check the error object to se if anything went wrong.
NSError *error;
[someObject someFunctionWithParam:paramOne andError:&error];
if ( error ) {
// Here you can inspect the error and act accordingly
NSLog(@"%@", [error localizedDescription]);
}
If you are the one implementing a method it usually looks something like this.
- (void)someFunctionWithParameter:(NSString *)argOne andError:(NSError **)error {
// something goes wrong
*error = [NSError errorWithDomain:@"SomeDomain" code:500 userInfo:@{@"infoKey": @"some info"}];
}
So about the title of your question. There is no catching NSError
's since they are not thrown. Only exceptions are thrown.