codable - What errors can happen when encode with Swift JSONEncoder -
jsonencoder
method func encode<t>(_ value: t) throws -> data t : encodable
throwable.
i'm wonder why throwable: if value encode not conform encodable
, should not pass compiler, should have no error happen @ runtime.
from jsonencoder
's source code:
/// - throws: `encodingerror.invalidvalue` if non-conforming floating-point value encountered during encoding, , encoding strategy `.throw`. /// - throws: error if value throws error during encoding.
debug descriptions errors:
top-level (t.self) did not encode values.
top-level (t.self) encoded null json fragment.
top-level (t.self) encoded number json fragment.
top-level (t.self) encoded string json fragment.
Comments
Post a Comment