开发者

Core Data: Errors vs Exceptions Part 2

My question is similar to this one, but I need further clarification. I often get exceptions during code like this:

NSError* error;
if (![managedObjectContext save:&error]) {
    NSLog(@"Failed to save to data store: %@", [error localizedDescription]);
}

However, when I pu开发者_开发技巧t a breakpoint in objc_exception_throw, I can find out that an exception is thrown in save:

(gdb) po [$eax name]
NSInternalInconsistencyException
(gdb) po [$eax description]
optimistic locking failure

I wouldn't expect this, since the docs say that an optimistic locking failure will return an error, not an exception.

As an aside, I can't even seem to catch this exception with @try ... @catch (NSException * e) in the code. It's all strange.


I think what's happening is that objc_exception_throw is catching internal exceptions in Core Data, but they really aren't percolating to my app. Because I set my merge policy, the locking failures are getting converted into object merges and all is well.

I should probably also use committedValuesForKeys: so I can see what's going on before the exceptions .. this doesn't happen every time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜