Carlos Ballesteros Velasco
05/23/2023, 9:42 PM//} 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?catch (e: Error) {
or catch (e: dynamic) {
. So I solved it like this:
@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!!
}
Igor Yakovlev
05/27/2023, 12:11 PM