Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios n即使发生';It’它裹着一层厚厚的布 //上下文是NSManagedObjectContext的一个实例 context.performAndWait{ 做{ guard context.has更改其他内容{ 返回 } 尝试context.save() }抓住{ 打印(“错误…”) } }_Ios_Swift_Core Data_Crash - Fatal编程技术网

Ios n即使发生';It’它裹着一层厚厚的布 //上下文是NSManagedObjectContext的一个实例 context.performAndWait{ 做{ guard context.has更改其他内容{ 返回 } 尝试context.save() }抓住{ 打印(“错误…”) } }

Ios n即使发生';It’它裹着一层厚厚的布 //上下文是NSManagedObjectContext的一个实例 context.performAndWait{ 做{ guard context.has更改其他内容{ 返回 } 尝试context.save() }抓住{ 打印(“错误…”) } },ios,swift,core-data,crash,Ios,Swift,Core Data,Crash,有人知道为什么包含try context.save()的行会导致以下崩溃吗 致命异常:NSInternalInconsistencyException此异常 NSPersistentStoreCoordinator没有持久存储(磁盘已满)。信息技术 无法执行保存操作 这是堆栈跟踪的一部分: Fatal Exception: NSInternalInconsistencyException 0 CoreFoundation 0x19d4c99d8 __except

有人知道为什么包含
try context.save()
的行会导致以下崩溃吗

致命异常:NSInternalInconsistencyException此异常 NSPersistentStoreCoordinator没有持久存储(磁盘已满)。信息技术 无法执行保存操作

这是堆栈跟踪的一部分:

Fatal Exception: NSInternalInconsistencyException
0  CoreFoundation                 0x19d4c99d8 __exceptionPreprocess
1  libobjc.A.dylib                0x1b184fb54 objc_exception_throw
2  CoreData                       0x1a33b42d8 -[NSPersistentStoreCoordinator _coordinator_you_never_successfully_opened_the_database_io_error:]
3  CoreData                       0x1a33b4370 -[NSPersistentStoreCoordinator _introspectLastErrorAndThrow]
4  CoreData                       0x1a33b49c8 __65-[NSPersistentStoreCoordinator executeRequest:withContext:error:]_block_invoke.797
5  CoreData                       0x1a324b408 -[NSPersistentStoreCoordinator _routeHeavyweightBlock:]
6  CoreData                       0x1a324c2d0 -[NSPersistentStoreCoordinator executeRequest:withContext:error:]
7  CoreData                       0x1a324c2fc -[NSPersistentStoreCoordinator executeRequest:withContext:error:]
8  CoreData                       0x1a324d270 -[NSManagedObjectContext save:]

抛出方法被包装在do-try-catch中,这应该可以防止应用程序崩溃,但是Firebase(Crashlytics)将此报告为崩溃。

NSException
s不由
do
/
catch
子句处理<代码>错误s不正确

不过,您可以使用Objective-C子句捕获
NSException
s,但通常它们对于从实际的根本问题中恢复是无用的;相反,他们只是压制它

如果您有这样一个异常,那么您在代码的其他地方犯了一个错误。要真正阻止异常发生,您需要修复该错误。在您的情况下,可以在堆栈跟踪中观察到问题:

Fatal Exception: NSInternalInconsistencyException
0  CoreFoundation                 0x19d4c99d8 __exceptionPreprocess
1  libobjc.A.dylib                0x1b184fb54 objc_exception_throw
2  CoreData                       0x1a33b42d8 -[NSPersistentStoreCoordinator _coordinator_you_never_successfully_opened_the_database_io_error:]
3  CoreData                       0x1a33b4370 -[NSPersistentStoreCoordinator _introspectLastErrorAndThrow]
4  CoreData                       0x1a33b49c8 __65-[NSPersistentStoreCoordinator executeRequest:withContext:error:]_block_invoke.797
5  CoreData                       0x1a324b408 -[NSPersistentStoreCoordinator _routeHeavyweightBlock:]
6  CoreData                       0x1a324c2d0 -[NSPersistentStoreCoordinator executeRequest:withContext:error:]
7  CoreData                       0x1a324c2fc -[NSPersistentStoreCoordinator executeRequest:withContext:error:]
8  CoreData                       0x1a324d270 -[NSManagedObjectContext save:]
\u协调员\u您从未成功打开\u数据库\u io\u错误

这暗示你的应用程序可能没有正确设置你的持久存储。也许,在应用程序的初始加载过程中,
NSPersistentStoreCoordinator
addPersistentStore
方法中发生了I/O错误,您没有处理该错误?

因为它不是
(NS)错误
,它是
NSInternalInconsistencyException
,是
NSException
。你抓不到他们。使用您的
do/try/catch
,您将捕获尝试过的方法抛出的
(NS)错误
此处
保存
。但这是一个崩溃,而不是抛出一个错误。这就是快速的解释。现在你看到了你的问题的区别:等等,这意味着你可能有一个更大的问题要解决,而不是简单的尝试/抓住。