Error Handling

get() and field reads throw DocumentDecodingException when a stored field can't be decoded — never a bare, low-level exception from the serialization layer.

try {
    val current = note.get()
} catch (e: DocumentDecodingException) {
    log.warn("note-1 field '${e.field}' failed to decode", e.cause)
}
Note

In practice this is rare — it only fires if a stored field is genuinely corrupted or was written by an incompatible old version of your app. You don't need a try/ catch around every single get() call; reach for one at a boundary that already handles unexpected failures (a repository layer, a top-level error handler), not around every read in your codebase.

What it wraps, and why

Because a document is decomposed into one MMKV key per field (see Field Decomposition), a single field can go bad — a corrupted byte range, a stale format from an old app version — while every other field in the same document stays perfectly healthy. DocumentDecodingException names the documentKey, the offending field when there is one, and wraps the underlying cause, which might otherwise have surfaced as a bare SerializationException, IllegalStateException, or IllegalArgumentException from the CBOR format. Your code catches one clean library exception type instead of reaching into the serialization layer's own error hierarchy.

What's not an error

A document that was simply never written is not a decoding failure — get() returns null for that case, it never throws just because something is missing. See Read & Write.