panicdefines how func panic(v interface{}), when called panic(anything), the string representation will be printed anything, and then the calling function stouttrace.
The only difference is that if you use recover, you can access everything that you panicked, for example :
func main() {
defer func() {
if err := recover(); err != nil {
if n, ok := err.(int); ok && n == 11 {
fmt.Println("got 11!")
}
}
}()
panic(11)
}
source
share