Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugger stops on core data save but no error output

I have a simple method that just takes two managed object IDs, pulls the managedObjects for them, makes a relation and then saves them into the managedObjectContext.

When I perform the save on the managedObjectContext, the debugger stops on the save line with an objc_exception_throw referencing the nsmanagedObjectContext save. Although there is no output in the nserror object that is output to give me any details as to why an exception is thrown. It also appears as if this save does work fine, which makes this even more confusing.

Here is the method in question...

- (void)relateLocationToInvite:(NSManagedObjectID *)locationID :(NSManagedObjectID *)inviteID {
NSManagedObject *invite = [self.managedObjectContext objectWithID:inviteID];
NSManagedObject *locationObj = [self.managedObjectContext objectWithID:locationID];
Location *location = (Location *)locationObj;

[invite setValue:location forKey:@"location"];
NSError *error = nil;
if( ![self.managedObjectContext save:&error] ){
    NSLog(@"Error relating a location to an invite %@",error);
}

}

like image 666
adam0101 Avatar asked Mar 20 '12 19:03

adam0101


1 Answers

If the execution of the application continues after the save: method without any problem (i.e. without throwing any uncaught exception and without reporting any error), that means the saving operation's implementation has caught the exception and decided to silently ignore it.

Why this happens is unclear: maybe the implementation relies on exceptions to report internal errors (this is not the way Objective-C exceptions should be used but some other languages make more use of exceptions). As long as the exception is caught before it reaches your own code, you should not worry about it.

If you want to know the reason of the exception, you may break on objc_exception_throw and use the following debugger command:

po *(id *)($ebp + 8)

This will display the NSException * parameter given to the function in the iOS Simulator (x86 architecture). On the device (arm architecture), the same result can be achieved using (if my memory serves my correctly):

po $r0
like image 195
Nicolas Bachschmidt Avatar answered Oct 13 '22 00:10

Nicolas Bachschmidt