Search code examples
iphoneobjective-cxcodecore-datansmanagedobjectcontext

NSManagedObjectContext save doesn't crash but breaks on objc_exception_throw


I am having the same issue described at this address http://www.cocoabuilder.com/archive/cocoa/288659-iphone-nsmanagedobjectcontext-save-doesn-crash-but-breaks-on-objc-exception-throw.html

I am debugging an application that uses Core Data with multithreading, and I have a breakpoint on objc_exception_throw and it hits this breakpoint in the call to save. (line 2 in code)

        NSError *error = nil;
        [self.managedObjectContext save:&error];
        if (error) {
            NSLog(@"Error : %@",error);
        }

I don't have any thing that is logged. I am using Xcode 4 with ios 4.0 -> 4.3. I think this is not related to Xcode/iOS version.


Solution

    • First, when using multithread with CoreData I had few problems when passing NSManagedObject around the app. Instead, as documented by Apple, I end up passing NSManagedObjectID and reconstruct the full object.
    • Second, when you don't have anything logged, it is likely related to memory issues, try to run the profiler especially, but not only, looking for 'Zombie', it should tell you more.
    • Finally, make sure you have initialized the context correctly, I had similiar problem because the model from momd file was not found and not loaded.