Skip to content

Instantly share code, notes, and snippets.

@akovardin
Forked from fipar/panic-recover.go
Last active July 2, 2018 20:51
Show Gist options
  • Save akovardin/fd55e9355a0bcc9a64e1 to your computer and use it in GitHub Desktop.
Save akovardin/fd55e9355a0bcc9a64e1 to your computer and use it in GitHub Desktop.
Panic/Recover
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