https://kotlinlang.org logo
k

kenkyee

03/25/2020, 11:00 AM
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

louiscad

03/25/2020, 11:59 AM
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

Nikolay Kasyanov

04/02/2020, 6:47 AM
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

louiscad

04/02/2020, 1:10 PM
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.