JS: add support of custom exceptions inherited from kotlin.Throwable that call super constructor from secondary constructor

This commit is contained in:
Alexey Andreev
2016-12-29 14:51:47 +03:00
parent f34093db9f
commit 6f4d8decc7
8 changed files with 78 additions and 19 deletions
@@ -17,5 +17,5 @@ fun box(): String {
return "OK"
}
return "fail: MyThrowable wasn't catched."
return "fail: MyThrowable wasn't caught."
}
@@ -0,0 +1,21 @@
class MyThrowable : Throwable {
val x: String
constructor(x: String, message: String, cause: Throwable? = null) : super(x + message, cause) {
this.x = x
}
}
fun box(): String {
try {
throw MyThrowable("O", "K")
}
catch (t: MyThrowable) {
if (t.cause != null) return "fail t.cause"
if (t.message != "OK") return "fail t.message: ${t.message}"
if (t.x != "O") return "fail t.x: ${t.x}"
return "OK"
}
return "fail: MyThrowable wasn't caught."
}