Files
kotlin-fork/compiler/testData/codegen/box/specialBuiltins/throwableImpl.kt
T
Zalim Bashorov aa2a4f0794 KJS: implement Throwable in Kotlin instead of use it as alias of JS Error
* Make it an inheritor of JS Error. Otherwise, Chakra engine doesn't fill stack trace of exception; In other engines inheritance has some good effects too.
* Copy all properties from internally created instance of JS Error

 #KT-6985 Fixed
 #KT-2328 Fixed
 #KT-8019 Fixed
 #KT-10911 Fixed
2016-11-17 16:22:27 +03:00

22 lines
545 B
Kotlin
Vendored

class MyThrowable(message: String? = null, cause: Throwable? = null) : Throwable(message, cause) {
override val message: String?
get() = "My message: " + super.message
override val cause: Throwable?
get() = super.cause ?: this
}
fun box(): String {
try {
throw MyThrowable("test")
} catch (t: MyThrowable) {
if (t.cause != t) return "fail t.cause"
if (t.message != "My message: test") return "fail t.message"
return "OK"
}
return "fail: MyThrowable wasn't catched."
}