开发者

Must I explicitely enable exceptions in Xcode?

开发者 https://www.devze.com 2023-01-02 19:15 出处:网络
-objectWithID: is supposed to give me an object that\'s broken when the ID doesn\'t exist. The documentation says, that this object throws an exception when I try to access an property.

-objectWithID: is supposed to give me an object that's broken when the ID doesn't exist. The documentation says, that this object throws an exception when I try to access an property.

However, it never throws any. Must I enable exceptions so that they're really thrown?

Here's some code:

// Assume: a new managed object has been created. Then it's ID has been converted to NSURL.
// The MO has been saved. Then the NSURL has been converted back to an NSMa开发者_运维技巧nagedObjectID *tmpID
// So tmpID is an ID that doesn't exist anymore, since the ID of the MO has changed due to persisting it
@try {
    NSManagedObject *mo = [context objectWithID:tmpID]; // tmpID doesnt exist anymore!
    NSString *timeStamp = [[mo valueForKey:@"timeStamp"] description]; // nil
    [mo setValue:[NSDate date] forKey:@"timeStamp"];
}
@catch (NSException * e) {
    NSLog(@"Error: %@: %@", [e name], [e reason]); // never called
}


How are you testing this? Core Data projects tend to have exceptions turned on by default.

What does your test look like?

Update

How do you know that tempID does not exist? Can you show the code that creates that tempID?

after saving, a tmpID turns into a permanent id, right? ...so when I convert it to NSURL to keep it around, and then convert it back after saving, it should be invalid...or not?

There is no guarantee of that. It would not surprise me if Core Data kept a lookup from the temp to the permanent for a while.

If you really want to see it throw an exception, change that temp to something else and throw that at Core Data. If you still don't get an exception after that then it is time to file a radar.

0

精彩评论

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