Skip to content

Instantly share code, notes, and snippets.

@dbbbit
Created March 28, 2017 14:31
Show Gist options
  • Save dbbbit/00f44857d29a1787c544c0d1a5fb1bcd to your computer and use it in GitHub Desktop.
Save dbbbit/00f44857d29a1787c544c0d1a5fb1bcd to your computer and use it in GitHub Desktop.
golang panic recover
package main
import (
"fmt"
"runtime/debug"
)
func f() (ret interface{}, err error){
var x interface{}
defer func() {
if err_ := recover(); err_ != nil {
fmt.Printf("%s %s", err_, debug.Stack())
}
}()
x = 1
return x.(bool), nil
}
func main() {
f()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment