dop251 / goja

ECMAScript/JavaScript engine in pure Go
MIT License
5.63k stars 378 forks source link

How to Throw an Error From the Golang Function #563

Closed gastraight closed 3 months ago

gastraight commented 8 months ago

Hi! While injecting a golang function into a js runtime how to throw an error js way within this function e.g.

    runtime := goja.New()
    runtime.Set("aFunc", func() {
               // how to throw an error here
        })
        runtime.RunString(`
              try {
                  aFunc()
              } catch (error) {
                  // so that to be able to catch it over here 
             }
        `)

Thx.