如果由于磁盘空间不足而导致域写入失败,则会引发什么错误

时间:2018-07-06 09:40:02

标签: android realm

我们正在尝试将大小为60-70MB的每个数据保存在多个领域中。当磁盘空间不足时,最好删除其中一个域。

如何识别领域抛出的错误是由于磁盘空间不足所致。

尝试模拟磁盘空间不足。我得到了下面的堆栈跟踪。

W/System.err: Caused by: io.realm.exceptions.RealmError: Unrecoverable error. write(): failed: No space left on device in /Users/Nabil/Dev/realm/master/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsSharedRealm.cpp line 101
        at io.realm.internal.OsSharedRealm.nativeGetSharedRealm(Native Method)
        at io.realm.internal.OsSharedRealm.<init>(OsSharedRealm.java:171)
        at io.realm.internal.OsSharedRealm.getInstance(OsSharedRealm.java:241)
W/System.err:     at io.realm.internal.OsSharedRealm.getInstance(OsSharedRealm.java:231)
        at io.realm.RealmCache.doCreateRealmOrGetFromCache(RealmCache.java:319)
        at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:282)
        at io.realm.Realm.getInstance(Realm.java:378)

要检查的代码段

try {
    // Insert data to realm
} catch (RealmError ex) {
    String detailMessage = ex.getMessage();

    if (detailMessage != null && detailMessage.contains("write()")
            && detailMessage.contains("No space left on device")) {

        // Time to delete old realm

    } else {
        throw ex;
    }
}

0 个答案:

没有答案