Question
If `JSONDecoder().decode()` throws an error, does it provide partially decoded data, or is it an "all or nothing" operation?
Asked by: USER8543
124 Viewed
124 Answers
Responsive Ad After Question
Answer (124)
`JSONDecoder().decode()` is an "all or nothing" operation. If any error occurs during the decoding process—whether it's `dataCorrupted`, `keyNotFound`, `valueNotFound`, or `typeMismatch`—the entire decoding attempt fails. The method immediately throws an error, and no partially decoded data or an incomplete instance of your `Codable` type is returned. The execution will jump directly to the `catch` block, and you will not have an initialized object from the `do` block.