How to catch non kotlin exception?


#1

kotlin generates type check in js catch block and rethrows if it fails. Is it possible to write non Throwable catch in kotlin without js("")?


#2

Kotlin Throwable is mapped to js Error. Or do you mean that non-Kotlin exception is not an Error?


#3

After some experimentation I discovered it is possible to do this

fun catchMe() {
    try {
        js("throw 'Some text'")
    } catch(e: dynamic) {
        println("Catched")
    }
}

Which generates js code I was searching for. Is it supported or I found a bug?

btw. What about C++/ SEH on native platforms. From my memories it is possible to throw anything. native will have dynamyc/**Any for integration?


#4

Cathing dynamic exception is a feature that was made intentionally. It’s desgined specially for catching exceptions that are not inherited from JavaScript Error.