In JS I had: ```//} catch (e: dynamic) { // @TODO...
# webassembly
c
In JS I had:
Copy code
//} catch (e: dynamic) { // @TODO: Check wasm
} catch (e: Throwable) {
all the exceptions I could get even if they are from JS are converted into Throwable?
1
Couldn't find a way to catch JS errors with:
catch (e: Error) {
or
catch (e: dynamic) {
. So I solved it like this:
Copy code
@JsName("Error")
external class JsError : JsAny {
    val message: String?
}

external interface JsResult<T : JsAny> : JsAny {
    val result: T?
    val error: JsError?
}

@JsFun("(block) => { try { return { result: block(), error: null }; } catch (e) { return { result: null, error: e }; } }")
private external fun <T : JsAny> runCatchingJsExceptions(block: () -> T): JsResult<T>

fun <T : JsAny> wrapWasmJsExceptions(block: () -> T): T {
    val result = runCatchingJsExceptions { block() }
    if (result.error != null) throw Exception(result.error!!.message)
    return result.result!!
}
i
Hi, yes, JS exceptions for now can not be catched in Kotlin generated Wasm code right now. So the best solution, I believe, is yours.