jsExternTryCatch
Helper for calling externally defined code in order to propagate a proper JS Error. On Kotlin/Js this simply calls block, but on Kotlin/WasmJs block is wrapped in a function call and run from Js within its own try/catch block. If an Error was caught, it is returned to Kotlin code, converted to Throwable, and then thrown.
NOTE: This should only be utilized for externally defined calls, not general kotlin code.
e.g.
internal external interface SomeJsThing {
fun doSomethingFromJs(): Int
}
fun executeFromKotlin(thing: SomeJsThing): Int {
return try {
jsExternTryCatch { thing.doSomethingFromJs() }
} catch(t: Throwable) {
println(t.errorCodeOrNull)
throw t
}
}
See also
Throws
If block throws exception
Helper for calling externally defined code in order to propagate a proper JS Error. On Kotlin/Js this simply calls block, but on Kotlin/WasmJs block is wrapped in a function call and run from Js within its own try/catch block. If an Error was caught, it is returned to Kotlin code, converted to Throwable, and then thrown.
NOTE: This should only be utilized for externally defined calls, not general kotlin code.
e.g.
internal external interface SomeJsThing {
fun doSomethingFromJs(): Int
}
fun executeFromKotlin(thing: SomeJsThing): Int {
return try {
jsExternTryCatch { thing.doSomethingFromJs() }
} catch(t: Throwable) {
println(t.errorCodeOrNull)
throw t
}
}
See also
Throws
If block throws exception
Helper for calling externally defined code in order to propagate a proper JS Error. On Kotlin/Js this simply calls block, but on Kotlin/WasmJs block is wrapped in a function call and run from Js within its own try/catch block. If an Error was caught, it is returned to Kotlin code, converted to Throwable, and then thrown.
NOTE: This should only be utilized for externally defined calls, not general kotlin code.
e.g.
internal external interface SomeJsThing {
fun doSomethingFromJs(): Int
}
fun executeFromKotlin(thing: SomeJsThing): Int {
return try {
jsExternTryCatch { thing.doSomethingFromJs() }
} catch(t: Throwable) {
println(t.errorCodeOrNull)
throw t
}
}
See also
Throws
If block throws exception