Howdy mate,
I’m experiencing using the syscall/js
package deal and I need assistance to discover a method to catch exception on a name to a js operate.
Right here an instance:
worth := js.World().Get("window").Get("localStorage")
...
When you disable the entry to the localstorage into your browser then it elevate the next exception:
with no method to resume your wasm code.
Thanks for any assist
The documentation of syscall/js
says that js.Worth.Get
panics when a worth shouldn’t be a JavaScript object, so it is best to be capable of “catch the exception” similar to you’d get well from a panic in different Go code:
func tryGet(v js.Worth, p string) (consequence js.Worth, err error) {
defer func() {
if x := get well(); x != nil {
var okay bool
if err, okay = x.(error); !okay {
err = fmt.Errorf("%v", x)
}
}
}()
return v.Get(p), nil
}