I'm using Ktor in a multiplatform project (Android...
# ktor
a
I'm using Ktor in a multiplatform project (Android + iOS) and I'm running into an issue with iOS where exceptions are not delivered the generated callback handler (callback handler accepts both an object and error), but instead uncaught and crashes the app. This is the error message that gets printed right before the stacktrace:
Copy code
Exception doesn't match @Throws-specified class list and thus isn't propagated from Kotlin to Objective-C/Swift as NSError
I've determined this happens because, in Kotlin, it's not required to specify if a function throws an exception. However, when targeting a native platform, if you don't specify that the function throws, those errors will be uncaught. So what I'm doing to resolve this is to add
@Throws(Throwable::class)
to every single API function I have. I'm wondering if there is an easier way to manage this since there's no lint type check for this (that I'm aware of), making it's easy to forget. I also feel like this may be more of a Kotlin question than a Ktor one.
m
This is exactly how you handle kotlin exceptions in ios, not specific to ktor. https://kotlinlang.org/docs/native-objc-interop.html#errors-and-exceptions