Jaroslav
11/07/2018, 12:59 PMthevery
11/07/2018, 1:17 PMJaroslav
11/07/2018, 1:19 PMsuspend fun <T : Any> call(command: Command<T>): T{
// here exception can be thrown
}
fun <T : Any> callAsync(command: Command<T>, context: CoroutineContext): Deferred<T> {
return GlobalScope.async(context) {
call(command = command)
}
}
ios runs callAsync, while exception is thrown inside suspend functionthevery
11/07/2018, 2:04 PMJaroslav
11/07/2018, 2:05 PMJaroslav
11/07/2018, 2:06 PMUnresolved reverence Throws
Jaroslav
11/07/2018, 2:26 PMJaroslav
11/07/2018, 2:27 PMolonho
11/07/2018, 2:44 PMsvyatoslav.scherbina
11/07/2018, 3:18 PM@Throws
annotation can’t be imported to common code. Instead you can declare it as expect annotation class
with actual typealias
.Konstantin Petrukhnov
11/08/2018, 6:31 AMJaroslav
11/08/2018, 6:56 AMJaroslav
11/08/2018, 7:32 AMinvokeOnCompletion(onCancelling:
which receives thrown error, but app crashes nonetheless with the same errorsvyatoslav.scherbina
11/08/2018, 7:47 AM// Common code:
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CONSTRUCTOR)
expect annotation class Throws(vararg val exceptionClasses: kotlin.reflect.KClass<out kotlin.Throwable>)
// Android code:
actual typealias Throws = kotlin.jvm.Throws
// iOS code:
actual typealias Throws = kotlin.native.Throws
svyatoslav.scherbina
11/08/2018, 7:47 AMI’ve now addedWhich one?which receives thrown error, but app crashes nonetheless with the same errorinvokeOnCompletion(onCancelling:
Jaroslav
11/08/2018, 7:47 AMsvyatoslav.scherbina
11/08/2018, 7:48 AMJaroslav
11/08/2018, 7:50 AMinvokeOnCompletion(onCancelling:
get’s called, printing error shows that’s the same one that was thrown, for now everything’s ok, but then after that callback is executed, app crashes with Uncaught Kotlin exception:
. Setting NSSetUncaughtExceptionHandler
doesn’t help either.Jaroslav
11/08/2018, 7:50 AMinvokeOnCompletion(onCancelling:
svyatoslav.scherbina
11/08/2018, 7:53 AMJaroslav
11/08/2018, 7:59 AMJaroslav
11/08/2018, 9:02 AMsvyatoslav.scherbina
11/08/2018, 10:23 AM@Throws
suspend fun anotherGreeting(): String {This is wrong.
@Throws
annotation must be applied to the function that is called from Swift directly.Jaroslav
11/08/2018, 10:23 AMJaroslav
11/08/2018, 10:26 AMsvyatoslav.scherbina
11/08/2018, 10:30 AM@Throws
annotation must be added to the function that is called from Swift and throws an exception.
In your case this function seems to be deferred.getCompleted()
.Jaroslav
11/08/2018, 10:50 AM@throws
svyatoslav.scherbina
11/08/2018, 10:55 AM@Throws
wrapper for deferred.getCompleted()
.Jaroslav
11/08/2018, 10:57 AMsvyatoslav.scherbina
11/08/2018, 10:58 AM@Throws
fun <T> getCompletedOrThrow(deferred: Deferred<T>): T = deferred.getCompleted()
Jaroslav
11/08/2018, 11:41 AMJaroslav
11/08/2018, 11:47 AMaakira
11/29/2018, 10:12 AMsvyatoslav.scherbina
11/29/2018, 10:19 AM@OptionalExpectation
(https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-optional-expectation/index.html) or declare a dummy actual annotation class Throws
for JS.aakira
11/29/2018, 10:30 AM