Commit 3c3292d5 authored by obscuren's avatar obscuren

Added recoverable option

parent 306b5bcf
...@@ -37,6 +37,8 @@ type Vm struct { ...@@ -37,6 +37,8 @@ type Vm struct {
BreakPoints []int64 BreakPoints []int64
Stepping bool Stepping bool
Fn string Fn string
Recoverable bool
} }
type Environment interface { type Environment interface {
...@@ -62,18 +64,20 @@ func New(env Environment) *Vm { ...@@ -62,18 +64,20 @@ func New(env Environment) *Vm {
lt = LogTyDiff lt = LogTyDiff
} }
return &Vm{env: env, logTy: lt} return &Vm{env: env, logTy: lt, Recoverable: true}
} }
func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) { func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
// Recover from any require exception if self.Recoverable {
defer func() { // Recover from any require exception
if r := recover(); r != nil { defer func() {
ret = closure.Return(nil) if r := recover(); r != nil {
err = fmt.Errorf("%v", r) ret = closure.Return(nil)
vmlogger.Errorln("vm err", err) err = fmt.Errorf("%v", r)
} vmlogger.Errorln("vm err", err)
}() }
}()
}
// Debug hook // Debug hook
if self.Dbg != nil { if self.Dbg != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment