https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
r

Ran

03/04/2023, 12:51 PM
There is a description in Objective-C interop: Note that the opposite reversed translation is not implemented yet: Swift/Objective-C error-throwing methods aren't imported to Kotlin as exception-throwing. So, I want to know how can I catch the error from the Objective-C function? For example. How can I catch
NSDecimalNumberDivideByZeroException
when I invoke
NSDecimalNumber.decimalNumberByDividingBy
function? I've used
runCatching
to wrap the invocation, but it doesn't work.
👀 1
g

Gijs van Veen

03/06/2023, 8:42 AM
You cant catch them unfortunately. From the docs:
Note that the opposite reversed translation is not implemented yet: Swift/Objective-C error-throwing methods aren't imported to Kotlin as exception-throwing.
So in the case of divide by zero, just check your divisor isnt zero before calling and throw your own exception
r

Ran

03/07/2023, 9:40 AM
OK, but this still is a flaw of kotlin multiplatform. We cannot check the errors in advance because some errors occurred in the platform-specific functions. Anyway, thanks to your response.
9 Views