mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-10 00:21:35 +00:00
36 lines
620 B
Kotlin
Vendored
36 lines
620 B
Kotlin
Vendored
// IGNORE_BACKEND_FIR: JVM_IR
|
|
public inline fun fails(block: () -> Unit): Throwable? {
|
|
var thrown: Throwable? = null
|
|
try {
|
|
block()
|
|
} catch (e: Throwable) {
|
|
thrown = e
|
|
}
|
|
if (thrown == null)
|
|
throw Exception("Expected an exception to be thrown")
|
|
return thrown
|
|
}
|
|
|
|
public inline fun throwIt(msg: String) {
|
|
throw Exception(msg)
|
|
}
|
|
|
|
fun box(): String {
|
|
fails {
|
|
throwIt("oops!")
|
|
}
|
|
|
|
var x = 0
|
|
try {
|
|
fails {
|
|
x = 1
|
|
}
|
|
}
|
|
catch (e: Exception) {
|
|
x = 2
|
|
}
|
|
|
|
if (x != 2) return "Failed: x==$x"
|
|
|
|
return "OK"
|
|
} |