Permalink
Browse files

recover panic

  • Loading branch information...
1 parent 2e623cc commit 71f65543b08f865a63dfd6eb37b843d7bc02957d @mattn committed Sep 25, 2013
Showing with 23 additions and 18 deletions.
  1. +23 −18 gopl/gopl.go
View
@@ -13,23 +13,28 @@ func main() {
var fset = token.NewFileSet()
r := bufio.NewReader(os.Stdin)
for {
- print("# ")
- line, err := r.ReadString('\n')
- if err != nil {
- break
- }
- code, err := world.Compile(fset, line+";")
- if err != nil {
- fmt.Fprintln(os.Stderr, err)
- continue
- }
- ret, err := code.Run()
- if err != nil {
- fmt.Fprintln(os.Stderr, err)
- continue
- }
- if ret != nil {
- println(ret.String())
- }
+ func() {
+ defer func() {
+ recover()
+ }()
+ fmt.Print("# ")
+ line, err := r.ReadString('\n')
+ if err != nil {
+ return
+ }
+ code, err := world.Compile(fset, line + "\n")
+ if err != nil {
+ fmt.Fprintln(os.Stderr, err)
+ return
+ }
+ ret, err := code.Run()
+ if err != nil {
+ fmt.Fprintln(os.Stderr, err)
+ return
+ }
+ if ret != nil {
+ fmt.Println(ret.String())
+ }
+ }()
}
}

0 comments on commit 71f6554

Please sign in to comment.