-
-
Save akovardin/fd55e9355a0bcc9a64e1 to your computer and use it in GitHub Desktop.
Panic/Recover
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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