I’m using CoreData in a multi-threaded iOS-app, and everything seems to work fine – unless I switch on the exception breakpoint in XCode. Whenever I do some CoreData-work, the breakpoint stops at the save:-method on NSManagedObjectContext – but the NSError is nil afterwards. I also have nothing in the log (except: Catchpoint 2 (exception thrown).), the app doesn’t crash… So it’s pretty hard to tell what’s going wrong.
The only clue I have is that I have a single object in updatedObjects: in my NSManagedObjectContext – but there seems nothing wrong with it.
My question is very similar to this question on stackoverflow
, but the only answer there doesn’t help me; I’m pretty sure that I’ve got everything covered there.
What could be wrong here? Or are there other possibilities to get some error information?
Thank you very much!
EDIT: showing code is pretty difficult. I’m loading objects with objectID, edit and store them in the context assigned to the current thread. I already checked – the context is always correct for the current thread; each thread has its own context, that shouldn’t be the problem. It would be even helpful if only someone could tell me how to get more information from that error/exception – or if I have to care about it after all. It seems to me as if the exception is catched within the `save´-method, so probably its a “normal” behaviour?
This is normal behavior. CoreData uses exception throwing & handling internally for some of its program flow. I talked to the CoreData people about this. It may seem odd, but that’s a design decision they made a long time ago.
When you hit the exception, make sure there’s none of your code in the backtrace between your call to
-[NSManagedObjectContext save:]and the exception being thrown. Calling-save:is very likely to call back into your code, e.g. if you’re observingNSManagedObjectContextObjectsDidChangeNotification, and if you’re doing bad things when you’re handling those notification, obviously you’re at fault.If you’re exiting the
-save:method, and the return value isYES, everything is good.Please note, that you should check the return value, do not use
error != nilto check for an error. The correct check is: