From the 1.4M1 release notes: "to make Swift code ...
# multiplatform
k
From the 1.4M1 release notes: "to make Swift code aware of expected exceptions, Kotlin functions should be marked with a @Throws annotation specifying a list of potential exception classes." Does this include runtime exceptions? E.g. IllegalStateException?
l
IllegalStateException
doesn't fall into the "expected exceptions" to me. If you don't declare a thrown exception, the app will crash. If the exception is likely to happen, you'll want to declare it, otherwise, if it's something normally impossible and it is okay to crash because it'd be an unrecoverable programmer error, then you can not declare it.
đź‘Ť 1
n
Let’s talk kotlinx.serialization. Errors while decoding JSON are expected IMO, although they are runtime exceptions, hence can’t be used with
@Throws
. Thoughts?
I wonder what’s the best practice here.
l
I think you can still declare
RuntimeException
and subclasses in
@Throws
. Otherwise, you can catch it a rethrow it wrapped in a non
RuntimeException
, or return an error type.