Skip to content

Instantly share code, notes, and snippets.

@fipar
Created November 28, 2012 21:45
Show Gist options
  • Save fipar/4164832 to your computer and use it in GitHub Desktop.
Save fipar/4164832 to your computer and use it in GitHub Desktop.
Basic example of panic / recover use in golang
package main
import (
"fmt"
"time"
)
func mainLoop() {
fmt.Println("starting main loop, this will die after dividing by 0")
i := 0
fmt.Println("%d",1/i)
}
func main() {
defer func() {
if err := recover(); err != nil {
time.Sleep(2 * time.Second)
main()
}
}()
mainLoop()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment