NSManagedObjectContext 保存不会崩溃,但会在 objc_exception_throw 上中断
我遇到了此地址中描述的相同问题 http://www.cocoabuilder.com/archive/cocoa/288659-iphone-nsmanagementobjectcontext-save-doesn-crash-but-breaks-on-objc-exception-throw.html
我正在调试一个使用 Core Data 进行多线程处理的应用程序,并且我在 objc_exception_throw 上有一个断点,并且它在调用保存时命中了该断点。 (代码中的第 2 行)
NSError *error = nil;
[self.managedObjectContext save:&error];
if (error) {
NSLog(@"Error : %@",error);
}
我没有记录任何内容。 我正在使用 Xcode 4 和 ios 4.0 -> 4.3.我认为这与 Xcode/iOS 版本无关。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
查看这个答案表明CoreData内部使用异常来管理其程序流。这就是调试器在 objc_exception_throw 处中断的原因。据我所知,没有办法禁用它。
编辑:从那时起,现在有一个解决方案可以忽略这些异常: 使用 Xcode 的 All Exceptions 断点时忽略某些异常
BTW:不要检查
error
而是使用返回的BOOL
值来确保保存调用成功。正确的做法是:Looking at this answer reveals that CoreData internally uses exceptions to manage their program flow. Thats why the debugger breaks at objc_exception_throw. As far as I know there is no way to disable this.
EDIT: Since then, there is now a solution to ignore these exceptions: Ignore certain exceptions when using Xcode's All Exceptions breakpoint
BTW: Do not check on
error
but use the returnedBOOL
value to ensure success of your save call. The correct way of doing this would be:在应用程序中传递 NSManagedObject。相反,正如记录的
Apple,我最终传递了 NSManagedObjectID 并重建了完整的
目的。
内存问题,尝试特别运行探查器,但不仅仅是寻找“僵尸”,它
应该告诉你更多。
类似的问题,因为未找到 momd 文件中的模型并且
未加载。
passing NSManagedObject around the app. Instead, as documented by
Apple, I end up passing NSManagedObjectID and reconstruct the full
object.
memory issues, try to run the profiler especially, but not only, looking for 'Zombie', it
should tell you more.
similiar problem because the model from momd file was not found and
not loaded.
我遇到了类似的问题,最终证明是由于 NSManagedObjectContextDidSaveNotification 的观察者被释放而没有将其从通知中心中删除。看来 CoreData 异常“隐藏”了当通知中心尝试通知任何对象占用由注册(但已释放)观察者释放的内存时引发的未知选择器异常。
I had a similar problem, eventually it turned out to be because of an observer of NSManagedObjectContextDidSaveNotification that was deallocated without removing itself from the notification center. It seems that the CoreData exception "hides" the unknown selector exception that is raised when the notification center tries notifying whatever object occupies the memory freed by the registered (but deallocated) observer.
最近我遇到了同样的问题:当尝试保存 ManagedObjectContext 时,应用程序崩溃,没有任何日志。
就我而言,有与上述完全不同的原因:
确保您没有在 Mac 上打开数据库管理器,这可能会锁定持久数据存储。
这(显然)也会杀死核心日期堆栈,而不会在代码或代码中引发任何可见错误日志。
结果我有一些未保存的更改,这使得数据库管理器锁定了存储。关闭数据库管理器解决了该问题。简单而愚蠢的错误,但我花了几个小时才弄清楚。
Recently I ran into the same issue: app crashing without any log, when trying to save managedObjectContext.
In my case there was a completely different cause from mentioned above:
Make sure you do not have DB Manager open on your mac, that could be locking the persistent data store.
This will (apparently) also kill the Core Date stack, without throwing any visible errors in code or in log.
Turned out I had some unsaved changes, which made the DB Manager lock the store. Closing the DB Manager fixed the issue. Simple and stupid error, but took me hours to figure out.
我碰巧遇到了这个问题,经过长时间的调试,我发现这是因为 NSError* 错误的重复声明,可能你在外部作用域中还有另一个 NSError* 错误,例如:
某些代码
然后错误将为零,尽管在事实上有一个例外。
I happened to meet this problem, and after long time debug I found it's because of a duplicate declaration of the NSError* error, may you had another NSError* error in the outer scope, like:
Some code
Then the error will be nil although in fact there is a exception.