我必须在Xcode中明确启用异常吗? [英] Must I explicitely enable exceptions in Xcode?

查看:141
本文介绍了我必须在Xcode中明确启用异常吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

-objectWithID:应该给我一个对象,当ID不存在时被打破。文档说,当我尝试访问属性时,此对象会抛出异常。

-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?

这里有一些代码:

// 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 NSManagedObjectID *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
}


推荐答案

你测试这个?

您的测试是什么样子?

您如何知道tempID不存在?你可以显示创建该tempID的代码吗?

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


保存后,tmpID变成永久ID,对吧? ...所以当我把它转换为NSURL保存,然后将其转换回保存后,它应该是无效的...或不是?

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?

不能保证。如果Core Data从临时文件到永久文件查找了一段时间,这不会让我感到惊讶。

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.

如果你真的想看到它抛出异常,到别的东西,并把它放在Core Data。如果你仍然没有得到一个例外,那么它是时候提交雷达。

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.

这篇关于我必须在Xcode中明确启用异常吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆