https://kotlinlang.org logo
#compose
Title
# compose
b

Brian Guertin

01/14/2022, 4:37 PM
The
completionHandler
for
suspend
functions only excepts an
Error
, but on the Kotlin side I want to catch a specific exception type e.g.
MyException
. How do I pass
MyException
to the
completionHandler
?
z

Zach Klippenstein (he/him) [MOD]

01/14/2022, 5:19 PM
Did you mean to post this in #coroutines ?
Which completion handler are you talking about?
b

Brian Guertin

01/14/2022, 6:51 PM
I'm using coroutines but this issue is not specific to coroutines in any way. When you write this in Kotlin:
Copy code
@Throws(MyException::class)
suspend fun myFunction(): Boolean
Then on the Swift/ObjC side, the function gets defined as
completionHandler(KotlinBoolean?, NSError?)
, so I'm not sure how to pass MyException over.
I ended up just changing my return type instead of dealing with it (so my return type now includes the error cases as well). I think what I'm asking for is just not supported by ObjC interop 🤷
Oh, but I did mean to post this in #ios, whoops
z

Zach Klippenstein (he/him) [MOD]

01/14/2022, 6:55 PM
ah, yea i know nothing about obj-c integration 😅
6 Views