mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 08:31:26 +00:00
35 lines
757 B
Kotlin
Vendored
35 lines
757 B
Kotlin
Vendored
// WITH_RUNTIME
|
|
// WITH_COROUTINES
|
|
import helpers.*
|
|
import kotlin.coroutines.experimental.*
|
|
import kotlin.coroutines.experimental.intrinsics.*
|
|
suspend fun suspendHere(): Any = suspendCoroutineOrReturn { x ->}
|
|
|
|
fun builder(c: suspend () -> Unit) {
|
|
try {
|
|
c.createCoroutine(EmptyContinuation).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
|
|
}
|