Make thread (not vm)'s error handling more robust.
@@ -111,21 +111,25 @@ func (t *thread) execRequiredFile(filepath string, file []byte) (err error) {
return
}
-func (t *thread) startFromTopFrame() {
- defer func() {
- if recover() == nil {
+func (t *thread) captureAndHandlePanic() {
+ switch e := recover().(type) {
+ case *Error:
+ if t.vm.mode == NormalMode {
+ fmt.Println(e.Message())
+ } else {
+ panic(e)
+ }
+ case error:
+ fmt.Println(e.Error())
+ case nil:
return
+ default:
+ panic(e)
}
-
- err, ok := recover().(*Error)
-
- if ok && t.vm.mode == NormalMode {
- fmt.Println(err.Message())
- } else {
- panic(err)
}
- }()
+func (t *thread) startFromTopFrame() {
+ defer t.captureAndHandlePanic()
cf := t.callFrameStack.top()
t.evalCallFrame(cf)
}
