Skip to content

Instantly share code, notes, and snippets.

@codemodify
Last active July 5, 2020 01:31
Show Gist options
  • Save codemodify/c4cce6ba45594f51f1c454472f32b424 to your computer and use it in GitHub Desktop.
Save codemodify/c4cce6ba45594f51f1c454472f32b424 to your computer and use it in GitHub Desktop.
go-recover-simple.go
package main
import (
"runtime/debug"
)
func main() {
// 1. set app crash handler
defer appCrashCatcher()
// 2. write your concurrent app
....
}
func appCrashCatcher() {
debug.SetPanicOnFault(true)
if err := recover(); err != nil {
fmt.Fprintf(os.Stderr, "\n\nCRASH: %v", err)
fmt.Fprintf(os.Stderr, "\n\nstack: %s", string(debug.Stack()))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment