Closed tiancaiamao closed 5 years ago
// (trap-error (+ 2 (simple-error "xxx")) (lambda X (error-to-string X))) res := Try(MakeNative(func(ctx *Trampoline, args ...Obj) { regXX := MakeString("xxx") regYY := PrimSimpleError(regXX) res := PrimNumberAdd(MakeNumber(2), regYY) ctx.Return(res) return }, 1)).Catch(MakeNative(func(ctx *Trampoline, args ...Obj) { err := args[0] res := PrimErrorToString(err) ctx.Return(res) return }, 1))
Use defer and panic to implement try-catch. trap-error may need this feature when translating the Shen code to Go.
defer
panic
try-catch
trap-error
Use
defer
andpanic
to implementtry-catch
.trap-error
may need this feature when translating the Shen code to Go.