Make initial continuation able to be resumed with exception

#KT-14719 Fixed
This commit is contained in:
Denis Zharkov
2016-11-09 12:15:38 +03:00
parent ae70a60a0a
commit 55508afb8c
5 changed files with 121 additions and 13 deletions
@@ -0,0 +1,33 @@
// WITH_RUNTIME
class Controller {
var exception: Throwable? = null
operator fun handleException(t: Throwable, c: Continuation<Nothing>) {
exception = t
}
suspend fun suspendHere(x: Continuation<Any>) {}
}
fun builder(coroutine c: Controller.() -> Continuation<Unit>) {
val controller = Controller()
c(controller).resumeWithException(RuntimeException("OK"))
if (controller.exception?.message != "OK") {
throw RuntimeException("Unexpected result: ${controller.exception?.message}")
}
}
fun box(): String {
var result = "OK"
builder {
suspendHere()
result = "fail 1"
}
builder {
result = "fail 2"
}
return result
}
@@ -0,0 +1,33 @@
// WITH_RUNTIME
class Controller {
suspend fun suspendHere(x: Continuation<Any>) {}
}
fun builder(coroutine c: Controller.() -> Continuation<Unit>) {
try {
val controller = Controller()
c(controller).resumeWithException(RuntimeException("OK"))
}
catch(e: Exception) {
if (e?.message != "OK") {
throw RuntimeException("Unexpected result: ${e?.message}")
}
return
}
throw RuntimeException("Exception must be thrown above")
}
fun box(): String {
var result = "OK"
builder {
suspendHere()
result = "fail 1"
}
builder {
result = "fail 2"
}
return result
}