can someone help me understand this section under ...
# multiplatform
o
can someone help me understand this section under the code? are they explaining the reasoning behind using the generic Exception class?
j
Yes. See docs. Because Kotlin doesn't have checked exceptions, but Swift only has checked exceptions, in order for exceptions to be caught in Kotlin and propagated in Swift as a checked exception, you have to declare the exceptions with a
@Throws
annotation, with the exception types that Kotlin should catch and propagate as checked exceptions. In this case, using
Exception::class
tells Kotlin to catch and propagate all
Exception
types as checked exceptions in Swift.
o
Ah so the type of exception can be whatever I want
@Throws is the mandatory part for iOS
j
Yes. Any exception type not included in the annotation won't propagate as checked and will terminate the program.
o
Oh it will outright crash when on iOS as if you didn’t handle it, cause not propagated, got it thanks
j
As a
suspend
function, it will propagate
CancellationException
automatically, without the explicit annotation. But any other expected exception type needs to be declared.