The debugger stops when saving kernel data, but does not display an error

I have a simple method that simply takes two identifiers of managed objects, pulls out managed objects for them, creates a relation, and then saves them to a managed object.

When I save to the managedObjectContext file, the debugger stops at the save line with objc_exception_throw, referring to the saving of nsmanagedObjectContext. Although there is no output in the nserror output object to give me any information on why the exception is thrown. It also looks like this salvation works great, making it even more confusing.

Here is the method ...

- (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); } 

}

+4
source share
1 answer

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

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

If you want to know the reason for the exception, you can break objc_exception_throw and use the following debugger command:

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

In this case, the NSException * parameter set by the function in the iOS simulator (x86 architecture) will be displayed. On a device (reinforcing architecture), the same result can be achieved using (if my memory serves me correctly):

 po $r0 
+8
source

Source: https://habr.com/ru/post/1402527/


All Articles