Files
kotlin-fork/js/js.translator/testData/box/expression/try/exceptionToString.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

27 lines
697 B
Kotlin
Vendored

package foo
class MyException(m: String? = null): Exception(m)
class MyException2(m: String? = null): Throwable(m)
fun check(e: Throwable, expectedString: String) {
try {
throw e
}
catch (e: Throwable) {
assertEquals(expectedString, e.toString())
}
}
fun box(): String {
check(Throwable(), "Throwable: null")
check(Throwable("ccc"), "Throwable: ccc")
check(Exception(), "Exception: null")
check(Exception("bbb"), "Exception: bbb")
check(MyException(), "MyException: null")
check(MyException("aaa"), "MyException: aaa")
check(MyException2(), "MyException2: null")
check(MyException2("aaa"), "MyException2: aaa")
return "OK"
}