https://kotlinlang.org logo
#ios
Title
# ios
p

Philipp Bykow

01/25/2022, 2:36 PM
Hello all. We have a KMM project and try to run the App on iOS but when executing the following error comes
Function doesn't have or inherit @Throws annotation and thus exception isn't propagated from Kotlin to Objective-C/Swift as NSError.
and crashes the App. In the class init we call something like this
Copy code
coroutineScope.launch {
    test()
}
The test function is as followed:
Copy code
@Throws(Exception::class)
    private suspend fun test() {
       ...
    }
k

kpgalligan

01/25/2022, 5:04 PM
Well, the short answer is you have a crash in your Kotlin code which makes its way to the “Swift/Kotlin” border, at which point it falls over. Whatever calls the
coroutineScope.launch
from Swift is failing. It’s probably wrapping and throwing whatever
test()
throws.
To just get logs, I’d wrap
coroutineScope.launch
call with try/catch, print that stack trace, then rethrow.
You should only add
@Throws
if you want to bubble errors up to Swift. However, you’ll need to use explicit
try
calls from Swift. Exceptions in that context are very different. We basically don’t use
@Throws
This isn’t directly about the topic, but sort of adjacent, about how the different platforms handle exceptions: https://www.kgalligan.com/crash-reporting-and-kmp/
p

Philipp Bykow

01/26/2022, 12:11 PM
Hello @kpgalligan, thank you i will try the try/catch you suggested.
2 Views